• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

submit buttons

i have 3 buttons on my htm page, submit  clear and default
if some hits enter on keyboard by default it should click submit button.
how to do this
0
shahrahulb
Asked:
shahrahulb
  • 2
  • 2
3 Solutions
 
GrandSchtroumpfCommented:
In common browsers, a form is submited when the enter key is hit inside a textfield (<input type="text">).
But that's not exactly the same as pressing the submit button because the value of the submit button will not be posted.
0
 
GrandSchtroumpfCommented:
If the server-side requires the "name" of the submit button to be passed in order to process the form, then you can just use that name on a "hidden" input instead of using it on the submit button.
0
 
BinylkumarCommented:
Hi,

Hope this helps you....

1. You can do using tabindex attribute to give preference to get focus...

Example 1

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>EnterName</td>
    <td><input type="text" name="textfield" tabindex="0"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit1" value="Submit" tabindex="1">
      <input type="submit" name="Submit2" value="Clear" tabindex="2">
        <input type="submit" name="Submit3" value="Default" tabindex="3"></td>
  </tr>
</table>

2 .You can do using JavaScript to take preference directly first to the submit button when the page is loaded....But this will help you to get focus first to the submit button....So whenever user entered into the page and press enter btn the submit btn will work first.....but this will not help to get data from the user.....So if you want to get data from the user best choice is using tabindex...

Example.2

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test</title>
<script language="javascript">
function focu(){
document.fc.Submit1.focus()
}
</script>
</head>

<body onLoad="javascript:focu();"><form name="fc" action="" method="">
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>a</td>
    <td><input type="text" name="textfield" tabindex="0"></td>
  </tr>
  <tr>
    <td>a</td>
    <td><input type="text" name="textfield" tabindex="1"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit1" value="Submit" tabindex="2">
      <input type="submit" name="Submit2" value="Clear" tabindex="3">
        <input type="submit" name="Submit3" value="Default" tabindex="4"></td>
  </tr>
</table></form>
</body>
</html>

Bye
Binylkumar
0
 
BinylkumarCommented:
Hi,

Working Example...

<form name="frmmy" id="frmmy" action="" method="post">
      Name <input type="text" name="txtname" id="txtname" value="">

      <input type="submit" name="cmdsubmit" id="cmdsubmit" value="Submit">
      <input type="reset" name="cmdClear" id="cmdClear" value="Clear">
      <input type="button" name="cmdDefault" id="cmdDefault" value="Default">
</form>

Bye
Binylkumar
0
 
DreamMasterCommented:
The most important thing to do, is only use 1 submit button, clearing your form is done with the <input type="reset"> the default button should simply be an <input type="button"> only the button actually used to submit the form should be <input type="submit">

Regards,
Max.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now