Link to home
Start Free TrialLog in
Avatar of shahrahulb
shahrahulb

asked on

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
Avatar of GrandSchtroumpf
GrandSchtroumpf

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.
SOLUTION
Avatar of GrandSchtroumpf
GrandSchtroumpf

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
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
ASKER CERTIFIED SOLUTION
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
SOLUTION
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