Form Submit issue with Image Button
Posted on | April 5, 2009 | No Comments
I have an html form in which submit and reset buttons are images. Reset button is using JavaScript to reset all the input fields to the default value. But when I press enter in any field than form submits by default. But before that the reset button also fires the JavaScript function and reset all the fields. How I can stop the reset button function before submitting the form. Here is the code i am using:
<form action="">
<label>Name</label>
<p>
<input />
</p>
<label>Address</label>
<p>
<textarea></textarea>
</p>
<p>
<label>Phone</label>
<input />
</p>
<p>
<input src="submit.gif" alt="Submit" />
<input src="reset.gif" alt="Reset" />
</form>
In the above page the gif buttons are only working visually. Form is submitting only due to its default behavior, when you enter in any input field. Form is submitting from both the buttons if you don’t put the JavaScript code to reset the form. But why reset code is also running while submitting the form?
I think you have to write code in JavaScript to submit like as to reset the form.
Comments
Leave a Reply
