Simple Question on HTML Form Submission
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 )
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<input type="submit" onclick="test();" id="mybutt">
<input type="button" onclick="clickHandler();" >
onclick is an event listener
click is an event
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 see.. so onclick() doesnt really simulate a button click event which would submit the form,but rather just calls the event handler function... Thanks!
Sorry, I should've explained myself better.
onclick is a property of DOM elements which usually stores a method.
So when you call
You are effectively doing nothing.
What you were attempting to do is accomplished by this code:
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!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread