If the user did not give any value to text box the value 0 (zero) to be set on blur but the text box should not display the value How can i do it using jquery
<g:textField name="distance" id = "distance" value="${tripInstance?distance}" min="0" class="number" />
You can’t as “value” is the display value.
Only way you be able to do it is intercept the form submission and prepopulate with default values if none are entered.
Failing that, the best place to hand it would be at the server end, ultimately where this kind of thing should happen.
That said, you should never rely on JavaScript to set/enforce default values as the user may not have JavaScript enabled or worse they are manipulating before sending it to you.
In that respect JavaScript should be considered dirty.
On second thoughts, you could do this:
I think, if nothing was entered into the “textField” it wouldn’t get sent back to the server, and therefore the hidden input field with the same name would take precedence.
The last most field of that name (which contains a value) will always be the one that is sent back to the server.