Jump to content

[SOLVED] Search function only works when "Enter" is pressed


deansp2001

Recommended Posts

Hi

 

Please can you look at

 

http://www.dacon.co.uk

 

The search function at the top of the site only works when the user presses "enter" after they have typed in what they want to search for. If the user clicks "go" then nothing happens.

 

The code used for this part of the site is as follows

 

<input type="text" name="keywords222" id="keywords2222" style="border:1px #333333 solid" value="Search this site..." onFocus="if(this.value=='Search this site...'){this.value=''}" onBlur="if(this.value==''){this.value='Search this site...'}" onKeyDown="if(window.event.keyCode==13){location.href='search4.php?keywords='+this.value;}" />
                  <input name="button222" type="button" style="border: 1px #ffffff solid;background-color:#2D76BB;color:#ffffff;font-weight:bold" onClick="location.href='search4.php?keywords='+document.getElementById('keywords').value;" value="Go" />

 

Doean anyone have any ideas as to what im doing wrong?

 

Thank you.

 

<input type="text" name="keywords222" id="keywords2222" style="border:1px #333333 solid" value="Search this site..." onFocus="if(this.value=='Search this site...'){this.value=''}" onBlur="if(this.value==''){this.value='Search this site...'}" onKeyDown="if(window.event.keyCode==13){location.href='search4.php?keywords='+this.value;}" />
<input name="button222" type="button" style="border: 1px #ffffff solid;background-color:#2D76BB;color:#ffffff;font-weight:bold" onClick="location.href='search4.php?keywords='+document.getElementById('keywords').value;" value="Go" />

 

You're using Javascript to detect the return key on the text box and onclick on the button.

 

If the person has Javascript disabled on their computer then the search box won't work - at all.

 

You also don't seem to have a <form> declaration anywhere that I can see. Try adding it.

Try this:

<form action="search4.php" method="get">
<input type="text" name="keywords" id="keywords2222" style="border:1px #333333 solid" value="Search this site..." onFocus="if(this.value=='Search this site...'){this.value=''}" onBlur="if(this.value==''){this.value='Search this site...'}" />
<input name="button222" type="submit" style="border: 1px #ffffff solid;background-color:#2D76BB;color:#ffffff;font-weight:bold" value="Go" />
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.