Link to home
Start Free TrialLog in
Avatar of dhite99
dhite99

asked on

How to submit form using <enter> key & without using a "type=submit" button

I have a form that has a text entry field. I am able to trap the onkeydown & enter key, but instead of triggering a click on a submit button, I'd like to submit the form wihtout having a "type=submit" button. Is there some way to, once the enter button is trapped, submit the form without the use of a submit button? Alternatively, is there some way to have a "type=submit" that is hiddent?
Here is the enter key trapping code and the form definition - note that I have it doing a click on the submit button, but I need to get rid of the button from the form and just take "enter" as submitting the form.

      $html = '<html>';
      $html .='<head>';
      $html .='<script type="text/javascript" language=javascript>';
      $html .= '<!--';
      $html .='document.onkeydown = fnTrapKeyDown;';
      $html .='function fnTrapKeyDown(e)';
      $html .='{ var intKeyPressed = document.all? event.keyCode: e.which;';
      $html .=' if(intKeyPressed == 13)  { document.getElementById(\'submit\').click();';
      $html .='return false;}';
      $html .='}';
      $html .='//-->';
      $html .='</script>';
      $html .='</head>';
      $html .='<body bgcolor=#d0d0d0><img border="0" src="inc/pnlogo.jpg" name="pnlogo" /><br />';
      $html .='<form action="maleftp.php" method="post">';
      $html .='<input type="text" name="smartsearch" size="10" maxlength="20" /><br />';
// want to get rid of the following submit button, need some way to submit form without having a submit button
      $html .='<input name="submit" type="submit" value="submit"/>';
      $html .='</form>';
                      echo $html;

ASKER CERTIFIED SOLUTION
Avatar of bugs021997
bugs021997
Flag of India image

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