Last day my friend had a problem...she had to do some extra work with the submit button other than embedding the parameter values to HTTP request. She had to clear the form contents before the form get submitted. So the basic question comes down to...
How do we change the behavior of Submit button of the HTML form ??
HTML form tag contains an intrinsic event attribute called onsubmit. The onsubmit event is fired on the click of the submit button. And the form does not get submitted if the expression returns a false (it gets submitted on all the other cases...whatever scrap U write in the expression)
So the only way to stop the html form from embedding the parameters to the HTTP request is to return a false from onsubmit event function should look something like the code below or something which does the same.
<`form action="were_is_the_next_page.jsp" onsubmit="return false;" />
Remember return false do not assign false ... Advise from someone who already fell into the pit..it was too dark out there.. :)
Typical example of using onsubmit button.
I want to reset the form after submitting the data.
resetFormSubmit = function(formObj)
{
formObj.submit();
formObj.reset();
return false();
}
<`form action="something.jsp" onsubmit="resetFormSubmit(this)" >
<`input type="text" name="myVal" />
<`input type=submit value="Submit"/>
<`/form>
Now what role does the return false do here...Try the code with no return false U will see that the request parameters gets filled with resetted value. Its because the form values get embedded to HTTP request twice..Once on the call of formObj.submit() and the second time after it comes out of the resetFormSubmit button.Thus the next page get called with resetted values.
Wednesday, October 29, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment