Just found out that invoking the onclick() of a SUBMIT button doesnt submit the form even though the function gets called and returns true. Here's a snippet. Can anyone tell me why? In this example, clicking the first INPUT submits,but doesnt submit on second INOUT click. (Guys, I know onclick() works only on IE,but that's not my point here )
Code:
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Why?</title>
</head>
<script>
function test()
{
return true;
}
function clickHandler()
{
document.getElementById("mybutt").onclick();
}
</script>
<body>
<form action="www.google.com">
<input type="submit" onclick="test();" id="mybutt">
<input type="button" onclick="clickHandler();" >
</form>
</body>
</html>
AND, if you are trying to do something at the time of form submission, you don't want to use an onclick listener on the submit button, you want an onsubmit listener on the form. Try having return false in your test() function and see if it makes any difference....it doesn't.
I've switched careers...
I'm NO LONGER a scientist,
but now a web developer...
awesome.
I see.. so onclick() doesnt really simulate a button click event which would submit the form,but rather just calls the event handler function... Thanks!
hmm..that's interesting..so onclick() just executes the event handler function,but click() executes the event..I just checked, click() works on all browsers.. thanks again!
Bookmarks