Jump to content

jimfog

Recommended Posts

In modern web design, in websites, I see that the search boxes have text in them, text thatgives a hint to the user as to what he can search for. You can see that in facebook for example, in the search box it says "search for friends,places, things...."., As I know the above(this "search for friends,places, things....".,) is the result of the value attribute of the input tag. What I want to know is how can adjust the behavior(regarding the text that appears in it) of the search box upon the user clicking there.At the w3schools site when you click inside that search box, the text/value(search w3schoools.com) is gone. Is this achieved with javascript or can be done with css to? Obviously we are talking here about an onclick event Thanks.

Link to comment
Share on other sites

Actually its onfocus AND onblur. onfocus is used and checks if current text input value is equal to default text input value, if so then hide, else show current text input value entered for user to change. onblur check if current text input value is empty, if so then reshow default text input value. <input type="text" value="Enter value" name="something" onblur="if(this.value == this.defaultValue || this.value == ''){this.value=this.defaultValue;}" onfocus="if(this.value == this.defaultValue){this.value=''}" >

Edited by dsonesuk
Link to comment
Share on other sites

So, you are saying that despite the user clicking on the search box is NOT a click event but an onfocus/onblur event.

Link to comment
Share on other sites

I am not talking about the case where you use the tab key, but about the case where you go the mouse cursorover the input element and then press the mouse click button. Is the above considered also onfocus?

Link to comment
Share on other sites

I don't what the problem is? focus means you select form element by CLICKING OR by keyboard TABBING, by keyboard or voice activation command. IF YOU WANT TO USE ONCLICK USE ONCLICK, BUT FOR ACCESSIBILITY YOU WOULD/SHOULD USE ONFOCUS INSTEAD. For one occasion for safari, or was it chrome, I found you have to use onclick to use a script to clear a form input type of 'file.

Link to comment
Share on other sites

I did, all the required coding, onfocus and onblur, thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...