Forum Moderators: open

Message Too Old, No Replies

disable submit form with return

         

Prinz

11:00 am on Mar 17, 2005 (gmt 0)

10+ Year Member



I have currently this submit for a form, however it is validating only when clicking the button, not when somebody is pressing "return".

<a href='javascript:if( check_form() ) document.formname.submit();'><img src="....">

Either I would like to disable the button "return" by using onclick (which I did not got to work) or to find a way that the javascript checking is used in both cases (pressing button/return).

thanks for your help

BlobFisk

11:36 am on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Prinz,

You can achieve this by puttin your validation script as being called as an onsubmit on the form tag, then using onKeyPress on your text field(s) and calling a function (returning to be exact) that sniffs for the Enter key being pressed (by using window.event.keyCode for example) and returns false on the form submit.

HTH

Prinz

12:50 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



even if I put the jacascript check in the form tag

<form name="form" action="form.php" onsubmit="check_javascript">

the input in the field is not controlled when simply pressing "return".

clicking the buttom to submit the document however it is controlled!

?

BlobFisk

1:02 pm on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Depending on how your form validator works, you may well need to do it this way:

<form ... onsubmit="return check_function()">

Prinz

9:45 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



thank you - it works now