I have an inputbox that has default value “enter keywords”. I also have two other checkboxes so users can either select checkboxes and hit search or type a keyword and search or do both. Just in case, they only select, checkboxes, I want to detect if nothing has changed in inputbox and set its value to empty. How do I do this in jquery?
<input name="KeywordBox" class="BasicSearchInputBox" type="text"
size="300" value="Enter Keywords"/>
Something like this???
if (~$("input").change(function ()) {do sth;}
Tried this: not working..
var keywords = encodeURIComponent($(".BasicSearchInputBox").val());
if (keywords.indexOf("Enter Keywords") != -1)
{
url += '&k=' + checkboxValues;
window.location.href=url;
}
if (keywords.indexOf("Enter Keywords") == -1){
window.location.href=url+'&k='+keywords+checkboxValues;
}
It sounds like you’re trying to do a watermark. Depending on your browser support requirements, you may want to take a look at the placeholder attribute. Allows for a nice watermark without actually changing the text box’s value. (There are numerous jQuery plugins that accomplish the same thing in a cross browser manner. )