Jump to content

onFocus Clear


GermanPrince

Recommended Posts

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

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

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

Archived

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

×
×
  • Create New...