Welcome to WebmasterWorld Guest from 54.146.191.2

Forum Moderators: incrediBILL

Message Too Old, No Replies

onclick varies between browsers

my onclick works in ie not in Chrome or Firefox

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

New User

joined:Apr 6, 2012
posts: 10
votes: 0


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
11:15 pm on Sept 23, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13432
votes: 389


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?
1:42 pm on Sept 24, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4993
votes: 14


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();">
3:08 pm on Sept 24, 2012 (gmt 0)

New User

joined:Apr 6, 2012
posts: 10
votes: 0


Thank you both.

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

Bill