Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1999-07-15
7
Medium Priority
?
246 Views
Last Modified: 2010-04-09
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.
0
Comment
Question by:SID68
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:davlun20080
ID: 1852004
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
0
 

Author Comment

by:SID68
ID: 1852005
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.
0
 
LVL 4

Expert Comment

by:brigmar
ID: 1852006
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.




0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SID68
ID: 1852007
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.

0
 
LVL 4

Accepted Solution

by:
brigmar earned 200 total points
ID: 1852008
well.... it works as you want in Netscape....
However, IE is submitting.

IE will submit any form that has a form element of the type "submit" when you press enter.

I can think of a non-javascript kludge, but it'll require server-side processing.

Turn the buttons into an image, and make that an input element. Pressing the image submits the form, with the co-ords of the mouse click. Not pretty.

Javascript still remains your best option.

Make v_Submit a hidden field, and turn the submit buttons into "button" buttons. Use an onclick handler for each button.. which will set v_Submit correctly, and submit the form.

<html><head>
<script language="javascript"><!--
function doClick(obj) {
 obj.form.v_Submit.value = obj.value;
 obj.form.submit();
}
//--></script>
</head><body>
<FORM ACTION="a.html" METHOD="GET">
<input type="hidden" name="v_Submit" value="none">
<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="button" NAME="come" VALUE="Come" onclick="doClick(this)"></TD>
<TD><INPUT TYPE="button" NAME="go" VALUE="Go" onclick="doClick(this)"></TD>
</TR>
</TABLE>
<BR>
<BR>

</FORM>
</body></html>


HTH

Brian
0
 
LVL 4

Expert Comment

by:brigmar
ID: 1852009
obvoiusly... put your oracle reference where I have "a.html"

Brian
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 6814520
Fixed the -1 problem on this question.
Escrow points corrected.

kb
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question