Page 1 of 1

Enter as default instead of button click in <FORM>

Posted: Fri Dec 26, 2003 1:06 pm
by anjanesh
I have a html file :

Code: Select all

&lt;HTML&gt;
&lt;HEAD&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;FORM ACTION="Query.php"&gt;
Name :
&lt;INPUT name=txtName&gt;
&lt;INPUT type="Submit" value="Search" name=SubmitBasicSearch&gt;
&lt;/FORM&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
Enter some name say John.

If we hit the enter key, it goes here :
http://localhost/Query.php?txtName=john

If we click then search button, it goes here :
http://localhost/Query.php?txtName=john ... rch=Search

In my php code of Query.php I have this

Code: Select all

<?php
if (isset($SubmitBasicSearch)) SearchName($txtName);
?>
Obviously this won't work if we hit the enter key. Only if the button is clicked then it'll work. So how do I resolve this ?
I already tried a javascript code for onkeypress in the txtName(gave id for that) and did document.open() etc etc but it didn't work either.
I do not want to do

Code: Select all

<?php
if (isset($txtName)) SearchName($txtName);
?>
because the actual page has multiple forms with same action link.

Thanks

Posted: Sat Dec 27, 2003 8:28 am
by volka
you might add an input/hidden that carries the data

Code: Select all

<INPUT type="hidden" value="Search" name="SubmitBasicSearch" />
<INPUT name="txtName" />
<INPUT type="Submit" value="Search" />