Nov 21, 2009

Enter Keypress Submits Wrong Button

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > HTML, XML etc..

Enter Keypress Submits Wrong Button

kvarnerexpress
Ive got a form, with a submit button on the left and a submit button on the right. By default on the enter keypress, the form submits the left submit button, but i want it to submit the right button. How would i accomplish this?
kvarnerexpress

Comment/Reply (w/o sign-up)

SystemWisdom
You should only have one submit button (type="submit") and make the other button a normal button (type="button") which has its own onclick event handler..

Example:
CODE


<html>
<head>
<script language="JavaScript"><!--

function doSubmit( e )
{
  var keyCode = (window.Event) ? e.which : e.keyCode;
  if( keyCode == 13 ) document.forms[0].submit();
}

function doSomethingElse()
{
   alert("Something else");
}

//--></script>
</head>

<body>

<form name="MyForm">

<input type="text" name="blah" value="" onkeypress="doSubmit(event)" />

<input type="button" value="Some Button" onclick="doSomethingElse()" />

<input type="reset" value="Clear" />

<input type="submit" value="Submit" />

</form>

</body>
</html>


I hope that helps!

 

 

 


Comment/Reply (w/o sign-up)

Mike
Or you could simply add an extra field to the code used to produce the submit button. Your submit button is probably <input type="submit" name="blah" value="Blah" />, but you can add an extra field that makes it so the user could click ALT then another letter or number to get it to work. For example:

<input type="submit" name="blah" value="blah" accesskey="r" />

would make it so if the user pressed down on ALT + 4, the button would b e clicked.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : enter, keypress, submits, wrong, button

  1. Multiple Drop Down Menus W/ Submit Button
    (9)
  2. Dynamic Button Size
    (1)
    In my application I have a custom tag that generates all the action buttons that the page needs. My
    problem is that in IE the space between the left side of the button and the image inside the button
    are not consistant. Some buttons have 3 or 4 more pixels of padding on the left side then others.
    This causes my buttons to be too large and hence the area the buttons are generated in stretches too
    far. I could wrap the buttons around to another line or add scroll bars.. but if it will fit in FF I
    think it should fit in IE as well. So my question is can I set the padding....
  3. Refresh Page After Back Button Hit
    (14)
    Hi. I have a page that is dynamically build through DOM manipulation. So, when I browse outside the
    page, and then click back, those dynamically created DOM objects are gone. Since I am also using JSP
    / Servlet technology, I can rebuild this page easily, which I have done. Here is my dilemma. If
    the user leaves the dynamic page, then clicks back on their browser, I need the page they are going
    back to to refresh. I can't figure out how to do this. I've tried using the META tag, but it
    won't do it. Help would be appreciated. Thanks. ....
  4. Submit Button
    (3)
    I have a form on my page. I do not have a submit button, but when I hit enter on my text field, it
    is like I am clicking on a submit button. My page refreshes to the original state, and my values are
    reset. I found this out because I made a submit button and tried it. Is there a way to get around
    this? I am trying to use a javascript that captures the key strokes. That works, but then the submit
    like event still fires after my code runs, nullifying any changes my code has made. html4strict
    Code: CODE 1.         2.             3.                 4.   ....
  5. Radio Button
    (5)
    I am trying to maintain the radio button selection on a Submit, but the form refreshes to its
    default selection. BTW, After a Submit is clicked, the radio form stays visible on the top of the
    screen while the query results are displayed on the bottom half of the screen (we're using an
    internal, embedded link). That's when the default selection comes into place. Any help would be
    appreciated. Please respond Kvarnerexpress.....
  6. Substitute Form Button For An Image
    homemade images in forms buttons (3)
    Hi, I have the next formular : CODE                                                  
                                                  I want to substitue the add button for an
    image CODE that i created but i want still to have the same funcitonlity when someone
    clicks. How can i do this? Thanks in advanced!....
  7. Button To Print Current Web Page
    (18)
    Hi, Does anyone know how to create a button that will printo out the current page. What I want to
    do is have the user fill out a form (containing name, address, zip, etc). They will then click on a
    "print" button and it will print out the form data. Any ideas? Thanks.....

    1. Looking for enter, keypress, submits, wrong, button

Searching Video's for enter, keypress, submits, wrong, button
See Also,
advertisement


Enter Keypress Submits Wrong Button

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com