deansp2001 Posted July 9, 2007 Share Posted July 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/ Share on other sites More sharing options...
albertdumb Posted July 9, 2007 Share Posted July 9, 2007 Have you tried using onSubmit ??? Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/#findComment-293215 Share on other sites More sharing options...
nick_whitmarsh Posted July 9, 2007 Share Posted July 9, 2007 It produces a javeascript error so either the button is getting mixed up with another javascript command on your page, or it is looking for an object which does not exist! Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/#findComment-293216 Share on other sites More sharing options...
Yesideez Posted July 9, 2007 Share Posted July 9, 2007 <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. Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/#findComment-293222 Share on other sites More sharing options...
Yesideez Posted July 9, 2007 Share Posted July 9, 2007 The search box fails on my PC - I can't use it at all! <form action="search4.php" method="get"> ...make your form here... </form> Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/#findComment-293227 Share on other sites More sharing options...
deansp2001 Posted July 9, 2007 Author Share Posted July 9, 2007 Thanks for your help, Ive added <form> tags to the start and end, but that diddnt make a difference, I then changed "onClick" to "onSubmit" but this made it not work at all. How can I re write it without Javascript? Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/#findComment-293251 Share on other sites More sharing options...
Yesideez Posted July 9, 2007 Share Posted July 9, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/#findComment-293255 Share on other sites More sharing options...
deansp2001 Posted July 9, 2007 Author Share Posted July 9, 2007 Works a treat - thanks very much for your assistance! Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/#findComment-293278 Share on other sites More sharing options...
Yesideez Posted July 9, 2007 Share Posted July 9, 2007 You're welcome! Don't forget to set the topic to "solved" Quote Link to comment https://forums.phpfreaks.com/topic/59064-solved-search-function-only-works-when-enter-is-pressed/#findComment-293280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.