|
-
Jun 21st, 2005, 07:04 AM
#1
Thread Starter
Lively Member
DOM onclick event not working in form?
A simple thing but i can't get it work.
What i want to achieve is just being able to get that message box when u click on the submit button in the form.
When i use the script below and i load the html page i immediately get the popup box and when i click the button nothing happens .
Can somebody help me out?
Code:
<html>
<body>
<form name="myForm">
The form's name is: <input type="text" name="text1" size="20">
<br /><br />
<input type="button" value="Show the form's name">
<script language="JavaScript" type="text/JavaScript">
document.forms[0].elements[0].onclick=window.alert('You clicked');
</script>
</form>
</body>
</html>
"Against All Odds"

-
Jun 22nd, 2005, 07:55 AM
#2
Addicted Member
Re: DOM onclick event not working in form?
hi choller,
just do this change and you'll make it.
Code:
<html>
<body>
<form name="myForm">
The form's name is: <input type="text" name="text1" size="20">
<br /><br />
<input type="button" value="Show the form's name" onclick="show()">
<script language="JavaScript" type="text/JavaScript">
function show() {
window.alert('You clicked');
}</script>
</form>
</body>
</html>
--Kishore...
-
Jun 22nd, 2005, 02:17 PM
#3
Member
Re: DOM onclick event not working in form?
You were accessing the first index of the elements array, which would be the text box, but i'm assuming this is what you were after.
Code:
<html>
<body>
<form name="myForm">
The form's name is: <input type="text" name="text1" size="20">
<br /><br />
<input type="button" value="Show the form's name">
<script language="JavaScript" type="text/JavaScript">
document.forms[0].elements[1].onclick = function()
{
alert('You clicked');
}
</script>
</form>
</body>
</html>
kishore.kr's works just as well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|