GermanPrince Posted July 21, 2010 Share Posted July 21, 2010 I'm trying to make it so when I select an input field it clears itself. It's not working though. Here is my code:html <input class="searchbox" type="text" name="searchFor" value="Search" onFocus="clear(this)" onKeyDown="return submitenter(this,event)" /> javascript function clear(input) { if (input.value == input.defaultValue) input.value = "";} Any suggestions? Link to comment Share on other sites More sharing options...
End User Posted July 21, 2010 Share Posted July 21, 2010 Try this:<input class="searchbox" type="text" name="searchFor" id="searchbox" value="Search" onFocus="getElementById('searchbox').value='';" />Or, more succinctly, this:<input class="searchbox" type="text" name="searchFor" id="searchbox" value="Search" onFocus="this.value='';" /> Link to comment Share on other sites More sharing options...
GermanPrince Posted July 21, 2010 Author Share Posted July 21, 2010 Thanks. Link to comment Share on other sites More sharing options...
thescientist Posted July 21, 2010 Share Posted July 21, 2010 i would just pass this to the clear function, use document.getElementById() on it and then set its value to "" Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.