Link to home
Start Free TrialLog in
Avatar of SID68
SID68

asked on

How to prevent hitting "Enter" from submitting...

Good [insert appropriate time here]!

I have the following problem:
I have to create a dialogue where the users have to enter an ID, a password and then have to chose one of 2 things, like yes or no.
Now, setting it up is easy: 1 textarea, 1 password-thingy on yes and on no button.
But, if you entered your password and hit enter, you always send the thing with "yes" (yes is the first button).
This should not happen. Enter should not be the same as pushing no, either (or neither (?)). So how can I prevent hitting Enter from submitting the form?

Thanks in advance.
Avatar of davlun20080
davlun20080

I belive this deals with forms in general, but you may try redefining the onKeyPress event for ENTER to call a function which will check the state of some radiobuttons.  This way you can check for the user input, requiring the user to check one of two radio buttons for example.  The people in the JavaScript section might be able to help with the script, unfortunately I know some of the logic but am not very good at the actual scripting yet.

davlun
Avatar of SID68

ASKER

Hmm. I forgot to mention an important thing. The whole thing is programmed on an Oracle database, hence I would prefer to the whole thing without Javascript, although it is possible.
SID68,

When a form only has one <INPUT> element, pressing Enter submits the form.

Do you need to use a textarea for the user id?

Change it to an <INPUT type="text" ... >

That will solve your problem, if it is acceptable to change the textarea to an <INPUT>.

otherwise, you'll need to use Javascript.




Avatar of SID68

ASKER

I guess I've been a bit unprecise. Here is the actual example:

<FORM ACTION="[some oracle procedure]" METHOD="POST">
<P>
<TABLE BORDER="0">
      <TR>
            <TD>UserID</TD>
            <TD><INPUT TYPE="TEXT" NAME="UserID" SIZE="25"></TD>
      </TR>
      <TR>
            <TD>Password</TD>
            <TD><INPUT TYPE="PASSWORD" NAME="PWD" SIZE="25"></TD>
      </TR>
      <TR>
            <TD><INPUT TYPE="SUBMIT" NAME="v_Submit" VALUE="Come"></TD>
            <TD><INPUT TYPE="SUBMIT" NAME="v_Submit" VALUE="Go"></TD>
      </TR>
</TABLE>
<BR>
<BR>

</FORM>

I hope this makes the problem clear.

ASKER CERTIFIED SOLUTION
Avatar of brigmar
brigmar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
obvoiusly... put your oracle reference where I have "a.html"

Brian
Fixed the -1 problem on this question.
Escrow points corrected.

kb
Community Support Moderator
Experts Exchange