Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Why does this code NOT execute ?

Reply
Thread Tools

Why does this code NOT execute ?

 
 
Alex
Guest
Posts: n/a
 
      01-29-2008
Hello, all.

Big question (for my very limited knowledge) - What's wrong with
this ? No error, but nothing happens:

HTML......................
<head runat="server">
<title>Test Page</title>
<script>
function radioButtonList2Click()
{
document.form1.radioButtonList1.SelectedIndex = -1;
}
</script>
<script>
function radioButtonList1Click()
{
document.form1.radioButtonList2.SelectedIndex = -1;
}
</script>
</head>


and

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (radioButtonList1.Attributes["OnSelectedIndexChanged"] == null)
{
radioButtonList1.Attributes.Add("OnSelectedIndexCh anged",
"javascript:radioButtonList1Click()");
}

if (radioButtonList2.Attributes["OnSelectedIndexChanged"] == null)
{
radioButtonList2.Attributes.Add("OnSelectedIndexCh anged",
"javascript:radioButtonList2Click()");
}
}
}

Thanks a lot
Alex
 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      01-29-2008
On Jan 29, 11:20 pm, Alex <(E-Mail Removed)> wrote:
> Hello, all.
>
> Big question (for my very limited knowledge) - What's wrong with
> this ? No error, but nothing happens:
>
> HTML......................
> <head runat="server">
> <title>Test Page</title>
> <script>
> function radioButtonList2Click()
> {
> document.form1.radioButtonList1.SelectedIndex = -1;
> }
> </script>
> <script>
> function radioButtonList1Click()
> {
> document.form1.radioButtonList2.SelectedIndex = -1;
> }
> </script>
> </head>
>
> and
>
> protected void Page_Load(object sender, EventArgs e)
> {
> if (!Page.IsPostBack)
> {
> if (radioButtonList1.Attributes["OnSelectedIndexChanged"] == null)
> {
> radioButtonList1.Attributes.Add("OnSelectedIndexCh anged",
> "javascript:radioButtonList1Click()");
> }
>
> if (radioButtonList2.Attributes["OnSelectedIndexChanged"] == null)
> {
> radioButtonList2.Attributes.Add("OnSelectedIndexCh anged",
> "javascript:radioButtonList2Click()");
> }
> }
> }
>
> Thanks a lot
> Alex


What language is that? It is not Javascript for sure. Looks a bit like
Microsoft JScript 7.0/8.0 with non-existing DOM methods. If it's one
of Microsoft ASP jargons, you may ask at
microsoft.public.scripting.jscript
If it is intended to be an universal Javascript code then please
explain the intended behavior and let's start to clean up.
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-30-2008
Alex wrote:
> Big question (for my very limited knowledge) - What's wrong with
> this ? No error, but nothing happens:
>
> HTML......................
> <head runat="server">


This may be one reason why nothing happens. Try removing the `runat'
attribute so that the scripts in the `head' element are executed client-side.

> <title>Test Page</title>


http://www.w3.org/QA/Tips/good-titles

> <script>


<script type="text/javascript">

See http://validator.w3.org/

> function radioButtonList2Click()
> {
> document.form1.radioButtonList1.SelectedIndex = -1;


This is probably another reason why nothing happens. Client-side properties
are more often case-sensitive (in ASP, server-side properties more often are
not, for compatibility to VBScript):

... .selectedIndex = -1;

If you use `.SelectedIndex' instead, the control object is added a
user-defined property that is not part of the DOM and therefore not
evaluated by the layout engine.

> [...]
> function radioButtonList1Click()
> {
> document.form1.radioButtonList2.SelectedIndex = -1;
> }


Same here.

> [...]
> protected void Page_Load(object sender, EventArgs e)
> {
> if (!Page.IsPostBack)
> {
> if (radioButtonList1.Attributes["OnSelectedIndexChanged"] == null)
> {
> radioButtonList1.Attributes.Add("OnSelectedIndexCh anged",
> "javascript:radioButtonList1Click()");
> }
>
> if (radioButtonList2.Attributes["OnSelectedIndexChanged"] == null)
> {
> radioButtonList2.Attributes.Add("OnSelectedIndexCh anged",
> "javascript:radioButtonList2Click()");
> }
> }
> }


This is C# or maybe J# code in ASP .NET that generates elements which
have event listeners attached to execute the above JScript code.
`OnSelectedIndexChanged' is a server-side event handler attribute of
Microsoft Web Controls.

http://msdn2.microsoft.com/en-us/lib...ge(VS.80).aspx

Probably `javascript:' should be omitted here, see the FAQ.


HTH

PointedEars
 
Reply With Quote
 
Joost Diepenmaat
Guest
Posts: n/a
 
      01-30-2008
Randy Webb <(E-Mail Removed)> writes:

> Thomas 'PointedEars' Lahn said the following on 1/30/2008 3:47 PM:
>> Alex wrote:
>>> Big question (for my very limited knowledge) - What's wrong with
>>> this ? No error, but nothing happens:
>>>
>>> HTML......................
>>> <head runat="server">

>>
>> This may be one reason why nothing happens. Try removing the `runat'
>> attribute so that the scripts in the `head' element are executed client-side.

>
> Even you should know that if that made it to the client, then the
> client ignores any attribute it doesn't understand and runat is not a
> valid attribute for the head element so it gets ignored. Has nothing
> to do with whether code gets executed on the client or not.


except that runat="server" is a server directive (for MS ISS I think),
which means that it could possibly prevent the code to reach the client.

I'm not sure what that code is supposed to do or even if it's
supposed to be JavaScript, though.

Joost.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM
ASP.Net VB code does not execute on postback (WebMatrix vs. not) Brian Miller ASP .Net 6 11-27-2004 02:24 PM
User control code behind does not execute Troy ASP .Net Building Controls 1 10-23-2003 12:36 AM



Advertisments