submit the form by clicking the button only.

J

jrefactors

When the user type something in text box, and press enter, it will
submit the form data
to test2.jsp, even without pressing submit form button. This is not
what I want, I want to
submit the form only when the user press the submit button. Any
workarounds? Please advise.
thanks!!


<script type="text/javascript">
function submit_me()
{ alert("submit me");
InputForm.submit();
}
</script>

<FORM NAME="InputForm" ACTION="test2.jsp" METHOD="POST">
name <input type="text" name="userName">
<input type="button" onClick="submit_me()" value="submit form">
</FORM>



<%= request.getParameter("userName") %>
 
G

Grant Wagner

When the user type something in text box, and press enter, it will
submit the form data
to test2.jsp, even without pressing submit form button. This is not
what I want, I want to
submit the form only when the user press the submit button. Any
workarounds? Please advise.
thanks!!


<script type="text/javascript">
function submit_me()
{ alert("submit me");
InputForm.submit();
}
</script>

<FORM NAME="InputForm" ACTION="test2.jsp" METHOD="POST">
name <input type="text" name="userName">
<input type="button" onClick="submit_me()" value="submit form">
</FORM>

You do not need JavaScript to submit the form. You might need JavaScript
to do what you are attempting to do (suppress the ability for the submit
to be invoked by the 'Enter' key), but you do not need it to submit the
form.

<!-- NO JAVASCRIPT NEEDED -->
<form name="InputForm" action="test2.jsp" method="POST">
name <input type="text" name="userName">
<input type="submit" value="submit form">
</form>

As for messing with browser functionality and preventing the 'Enter' key
from submitting the form, you can find multiple variations of that theme
at:

<url:
http://www.google.ca/search?q=javascript+prevent+enter+key+submit+form
/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top