I have search functionality in my app, in which when user clicks in textbox,
the text in the text box disappers. This works perfectly in chrome(6.0) but does not disappear after click in mozilla firefox(3.6) why?
// here is the code:
echo "Search: ";
echo "<input type=\"text\" class=\"smalltxt\" name= \"srchtxt\" id= \"srchtxt\" value= \"enter username\" height=\"20px\" onfocus= \"javascript:areaOnFocus(srchtxt, 'enter username');\" onblur= \"javascript:areaOnBlur(srchtxt, 'enter username');\" />";
// function called:
function areaOnFocus(element, inputText)
{
if(element.value == inputText)
{
element.value='';
}
}
function areaOnBlur(element, inputText)
{
if(element.value=='')
{
element.value = inputText;
}
}
Thank you in advance.
First, you don’t need
javascript:in the inline event handlers.Secondly, try to pass
thisinstead ofsrchtxtas the first argument for both functions.Passing just
srchtxtprobably causes the browser to find the element with the specifiedname, but this doesn’t work in Firefox if I remember well.The final code should look like this:
EDIT: @down: this is impossible, because I’ve tried the following code:
in my Firefox 3.6.10 and it worked well – when the page has loaded, the input’s value was “enter username”. When I clicked it, the text disappeared. And when I left the field empty and removed the focus, “enter username” appeared again in it. So…