Forum Moderators: open

Message Too Old, No Replies

onclick varies between browsers

my onclick works in ie not in Chrome or Firefox

         

bs6600

3:59 pm on Sep 23, 2012 (gmt 0)

10+ Year Member



Is there a routine explanation for this or what

Typically I have

function f_button()
{alert("hello")}
.
.
.
<INPUT TYPE="radio" name="radiobuttons" id="radiobutton3" VALUE=0 onClick="f_button()">


The alert fires in IE but not in Chrome or Firefox

Thanks
Bill

lucy24

11:15 pm on Sep 23, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Off the top of my head without detour to experiment:

#1 CASE
#2 Quotation marks

All versions of IE, Chrome, FF, or just whichever copy you currently have on your own computer?

Fotiman

1:42 pm on Sep 24, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The following works for me in all browsers:

<html>
<head>
<title>
Test
</title>
</head>
<body>
<form action="">
<div>
<INPUT TYPE="radio" name="radiobuttons" id="radiobutton3" VALUE=0 onClick="f_button()">
</div>
</form>
<script>
function f_button() {
alert("hello");
}
</script>
</body>
</html>

Note, however, that I would not use inline event handlers. Instead, attach event listeners via the script code... don't muddle your HTML with scripting content.
Also, you should consider cleaning up your code with respect to what lucy24 pointed out. You've got mixed case, and inconsistent use of quotes around HTML attribute values. Your code should look more like this when cleaned up:


<input type="radio" name="radiobuttons" id="radiobutton3" value="0" onclick="f_button();">

bs6600

3:08 pm on Sep 24, 2012 (gmt 0)

10+ Year Member



Thank you both.

I have it working now with 'case' burned into my fingertips!

Bill