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;
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(\'
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.webdeveloper.com/forum/showthread.php?t=52300