Hi all,
I'm having just a heck of a time trying to set the onClick action of a form element using Javascript. Spent most of the morning Googling and all indications are that the code below should work, but it doesn't. I'm probably complicating the issue by coding on a Mac (the only comp available), but on the Mac, I'm getting a "document.getElementById(...) is not an object" error when loading the page.
I've apparently overworked my thinker... can anyone help me out with this?
Thanks much,
Chuck
I'm having just a heck of a time trying to set the onClick action of a form element using Javascript. Spent most of the morning Googling and all indications are that the code below should work, but it doesn't. I'm probably complicating the issue by coding on a Mac (the only comp available), but on the Mac, I'm getting a "document.getElementById(...) is not an object" error when loading the page.
I've apparently overworked my thinker... can anyone help me out with this?
Thanks much,
Chuck
Code:
<html>
<head>
<script type="text/javascript">
<!--
document.getElementById('x').onclick = function() {alert('beep');}
-->
</script>
</head>
<body>
<form>
<input type="button" name="x" id="x" value="click" />
</form>
</body>
</html>