I've no idea why this isn't working, but I'm sure it's a very common bit of Javascript. My syntax is clearly lacking, and I don't know why:
<input type="text" value="search" id="search" name="q" onclick="javascript:if($(this).val() == 'search') {$(this).val() = '';} return false;" />
It should be like this:
<input type="text" value="search" id="search" name="q" onclick="javascript:if($(this).val() == 'search') {$(this).val('');} return false;" />
correct way : $this.val('');
incorrect way : $this.val() = '';
Your issue is with this line of code:
$(this).val() = ''
The proper way to set a value in jQuery is:
$(this).val("Your value here");
In addition, inline JS is never a good idea. Use this instead:
$("#search").on("click", function() {
if ($(this).val() == "search")
$(this).val("")
});
Here's a working fiddle.
References: jQuery .val()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With