Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<form method="get" action="https://www.google.com/search">
<input type="text" name="q" size="50" value="Search Google..."> <input type=submit value=Search></input>
</form>
Posted
Comments
Sergey Alexandrovich Kryukov 19-May-15 16:07pm    
Please define "unclicked". :o)
—SA

1 solution

There is NO unclicked. From your example I understood that you want to put back "Search Google..." when input text box loses focus (user clicks away from the input text box).

But you might want to put back the default text (Search Google...) only if the user does not enter any value in the text box and clicks away. Also you might want to clear the text only if it is not your default text in the text box.

Here are the links for click and blur event handlers in jQuery.

https://api.jquery.com/click/[^]
https://api.jquery.com/blur/[^]

For getting and setting value of input, refer the .val() function of jQuery.
http://api.jquery.com/val/[^]

Since you have used name attribute, you can use attribute selector to find the control and add the event to it.

https://api.jquery.com/attribute-equals-selector/[^]

Code Sample:
Click event with attribute selector:
$("input[name='q']").click(function(){
  //your code
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900