Pressing "Enter" to submit form
I've got a search form that users enter a stock code then click search and the results are displayed. My problem is a lot of users enter the stock code then hit "Enter" but with my checking (below) is doesn't think the search button has been clicked.
How can I capture "Enter" being pressed so I can perform the required search?
PHP Code:
//Check if form has been submitted
if (!isset($_POST['submit']) ) {
//display search form
}
else {
//Show search results
}
Re: Pressing "Enter" to submit form
You don't "capture" the enter in a web application. Clicking on the button or pressing enter will yield the same result.
It depends on how your HTML is setup. If it's in the same form, pressing enter should submit the form (unless it's a textarea).
Also, I've never been a fan of isset. I like checking for nulls :D
Re: Pressing "Enter" to submit form
Thanks kasracer. I have a textbox as the only item in the form (along with submit button) If I type a stock code then hit enter the page re-loads but shows the search page again instead of search results.
This is my code.
PHP Code:
<form method="post" action="<?php echo $PHP_SELF;?>">
<table width="25%" border="0" cellpadding="2" cellspacing="1" bgcolor="cccccc"><tr>
<td width="50%"><b>Stock Code:</b></td>
<td width="50%"><input name="code" type="text" maxlength="5" size="5"></td>
</tr>
<tr>
</table><br>
<input type="submit" name="submit" value="Search" style="font-size: 8pt; font-weight: bold">
</form>
Re: Pressing "Enter" to submit form
No idea why enter just doesn't work then. I take it you don't have some sort of page accessable to us, do you? Does it work correctly in any web browsers?
1 Attachment(s)
Re: Pressing "Enter" to submit form
Attached is a page with all the code.
It works in Mozilla but not IE :confused:
Re: Pressing "Enter" to submit form
It might be because the Submit button is outside of the table and the text field is inside the table.
Re: Pressing "Enter" to submit form
No such luck :(
Does it work for you in IE?
Re: Pressing "Enter" to submit form