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.

 

Link to comment
Share on other sites

<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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.