jeger003 Posted March 28, 2009 Share Posted March 28, 2009 im trying to create a search field......where it would say "Search...." and when the user clicks the field the "Search..." would disappear and if they clicked out it would return the "Search..." i think there is a way to do it with onfocus....i would appreciate any help or links to help thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/151532-anyone-know-how-to-use-onfocus/ Share on other sites More sharing options...
ToonMariner Posted March 28, 2009 Share Posted March 28, 2009 I suggest you have a look at using jquery - if you do then managing this stuff is dead easy... http://docs.jquery.com/Events/focus Quote Link to comment https://forums.phpfreaks.com/topic/151532-anyone-know-how-to-use-onfocus/#findComment-795885 Share on other sites More sharing options...
haku Posted March 30, 2009 Share Posted March 30, 2009 I agree with Toon Mariner. But if you really want to do it by hand, then you have to check the value of the input when the field is 'focused on', and if it is the default value, then set the value of the field to be empty. Quote Link to comment https://forums.phpfreaks.com/topic/151532-anyone-know-how-to-use-onfocus/#findComment-796624 Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 this is javascript, not HTML, but ... <input type="text" value="Search..." onFocus="this.value='' "> note, after this.value are two single quotes, not a double quote Quote Link to comment https://forums.phpfreaks.com/topic/151532-anyone-know-how-to-use-onfocus/#findComment-796856 Share on other sites More sharing options...
haku Posted March 31, 2009 Share Posted March 31, 2009 The only problem with that code is that it will always delete the value of the field after it is clicked on. So if a person realizes they missed a letter and want to go back to add it, when they click on the field, everything they entered will be deleted. This is why a check to see if the current value is the default value is necessary before deleting the value. Quote Link to comment https://forums.phpfreaks.com/topic/151532-anyone-know-how-to-use-onfocus/#findComment-797447 Share on other sites More sharing options...
Andy-H Posted March 31, 2009 Share Posted March 31, 2009 <input type="text" name="search" value="Search..." onfocus="if (this.value == 'Search...'){ this.value = ''; }" onblur="if (this.value == ''){ this.value = 'Search...'; }" > Quote Link to comment https://forums.phpfreaks.com/topic/151532-anyone-know-how-to-use-onfocus/#findComment-797457 Share on other sites More sharing options...
jeger003 Posted April 2, 2009 Author Share Posted April 2, 2009 hey guys, i apologize i have replied my comp been messed up....i just want to take the time and thank you all for the help I greatly appreciate it. @andy-h thank you for the code works GREAT!! thanks again everyone!!! Quote Link to comment https://forums.phpfreaks.com/topic/151532-anyone-know-how-to-use-onfocus/#findComment-799732 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.