I have an input field that has a default value added with JavaScript
<input type="text" class="input-text required-entry validate-value-eg" id="city_field" name="city" onfocus="if(this.value=='e.g. Bristol, Yorkshire') this.value='';" onblur="if(this.value=='') this.value='e.g. Bristol, Yorkshire';" value="e.g. Bristol, Yorkshire">
Whenever visitor click on this field the default value will dissipated and restore if not replaced by other value.
What I am trying to achieve is to add a class only if value has been changed from default?
Any help much appreciated,
Thanks
Dom
It is always a better practice to define your events in the script section or a separate .js file.
You don’t need to handle that in a
.change()event . You can check that in the.blur()event itself..HTML
Pure Javascript
Javascript Fiddle
But you can achieve this with a loss lesser code by using other javascript frameworks.
This will make your life a lot easier but it is always good if you start out with javascript.
jQuery
jQuery Fiddle