PDA

View Full Version : form question


xiaodao
12-26-2004, 02:37 AM
this question may appear quite stupid, i really dont know how to do it
:) i am still newbie

<table width=180 cellpadding=0 cellspacing=0>
<form name=searchuser method=post action=setuser.php>
<tr>
<td>
<input type=text name=username>
</tD>
<td>
<input type=submit name=submit value=search>
</tr>
</form>
</table>
<?
if($_POST[submit]) {
echo $_POST['username'];
}?>

the question is when i press enter key on my keyboard nothing appear unless i press my mouse on the button, why this happens? how to solve

Fou-Lu
12-26-2004, 09:07 AM
Assuming that you have your form highlighted (either you have entered your cursor onto the text input, or you can see that the "search" is highlighted), than I'm sort of at a loss for this one.
You really should be quoting your elements as well though. If worst comes to worst you may just have to anchor your submit buttons with an accesskey so that your user can press alt+s for instance to submit. (Which really isn't worse, I'd recommend doing it in either case).
The only time your code like this should present a problem is if its within a <textarea> tag, as then it will take your enter as being a new line instead. Other than that, I'm not sure, but it is an HTML problem not a php problem.

Brandoe85
12-26-2004, 11:36 AM
It's not a php problem but you can do it with javascript. You can detect which key is pressed and then submit the form. I havn't done anything like this in a while but im thinking this will work:

<table width="180" cellpadding="0" cellspacing="0">
<form name="searchuser" method="post" action="setuser.php">
<tr>
<td>
<input type="text" name="username" onFocus="if(event.keyCode==13)document.searchuser.submit();">
</tD>
<td>
<input type="submit" name="submit" value="search">
</tr>
</form>
</table>
<?
if($_POST[submit]) {
echo $_POST['username'];
}?>

BTW: like Fou-Lu said, you really should be using quotes with your html.

xiaodao
12-26-2004, 11:59 AM
do you all have this problem? i got see the search button highlighted, but i press enter nothing appear, really strange

Fou-Lu
12-28-2004, 04:21 AM
Indeed that is odd.
Do you have an example page that we can see?