Reputation: 3974
When I click the 'CLEAR' button, I want the javascipt code to run. It does run but then the form gets submitted. Is there a way to stop the form from getting submitted? Or is there a spring standard to clear the form. I just thought it would be faster if I did it on the client-side.
<input type="submit" value="CLEAR" onclick="javascript:clearForm()"/>
The above code appears inside the spring form tag.
Upvotes: 0
Views: 2531
Reputation: 193291
Two options.
1). Using input type="button"
:
<input type="button" value="CLEAR" onclick="clearForm()"/>
2). Using input type="reset"
instead of clearing the form with javascript.
<input type="reset" value="CLEAR" />
Upvotes: 3
Reputation: 2941
Change
<input type="submit"
to:
<input type="button"
That will stop your form being submitted when the button is clicked.
Upvotes: 2