OnChange Javascript - IE vs Firefox

B

Bruno Alexandre

Hi Guys,

I'm having a HUGE problem with Javascript under IE, the code below belongs
to a page
http://filterqueen.brinkster.net/test.aspx

it works fine under Firefox, but not in IE...

does anyone knows how to add OnChange Script to work under IE as well?

-----------------------------------------
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
rbl.Attributes.Add("onchange", "javascript: alert('me :)');")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:RadioButtonList runat="server" ID="rbl" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Text="1" ></asp:ListItem>
<asp:ListItem Value="2" Text="2" ></asp:ListItem>
<asp:ListItem Value="3" Text="3" ></asp:ListItem>
</asp:RadioButtonList>
</form>
</body>
</html>
 
R

Ray Booysen

For one thing, your script is incorrect. You can remove the
"javascript:" portion.
 
B

Bruno Alexandre

nop...

You are wrong.

1st we need to supply the language, like if you wanna print the page you
scecified

<a href="javascript: window.print();" >

and not only window.print(); ...

thans a W3C thing!


and secondly, even if I delete it still doesn't work :-(
 
B

Bruno Alexandre

and one more...

it's ONLY FOR RadioButtonList...

all my DropDownList are working perfectly with that syntax, in IE and
Fireworks!
 
H

Hans Kesting

For one thing, your script is incorrect. You can remove the "javascript:"
nop...

You are wrong.

1st we need to supply the language, like if you wanna print the page you
scecified

<a href="javascript: window.print();" >

and not only window.print(); ...

thans a W3C thing!

and secondly, even if I delete it still doesn't work :-(

Not quite (as I see it):
A "href" usually has a URL in it, so it needs to be told that it
shouldn't redirect the browser to some URL, but execute a script
instead.
An "onclick" (onchange, onmouseover, onkeyup and other "on*"
attributes) doesn't redirect by itself, it is *designed* to execute a
script. That's why you don't need to tell it that it is javascript.

so :
<a href="javascript:alert('href')" onclick="alert('onclick')">X</a>


Hans Kesting
 
B

Bruno Alexandre

got it...


but still, my problem remains...

but I follow the link that Ray sent and I found that the RadioList is
compiled as an SPAN tag, so that's why the JS didn't work, because onChange
is not valid under a span tag

from this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
rbl.Attributes.Add("onChange", "alert('me :)');")
End Sub

I changed to this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim i As Integer
For i = 0 To rbl.Items.Count - 1
rbl.Items(i).Attributes.Add("onChange", "alert('me :)');")
Next
End Sub

and now it works fine :)
 
G

Greg Collins [Microsoft MVP]

In IE onchange applies to INPUT TYPE=text, SELECT, and TEXTAREA.

Perhaps you need to use onpropertychange instead?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top