Stack Stack - 2 years ago 185
HTML Question

How to set default value of input if value is empty? jQuery

Example, i have input where default value is 5.
But user remove it using backspace, so after that i want to set default value again.

Answer Source

Lets say your input is having a id test you can do like below

$('#test').on('change blur',function(){
      if($(this).val().trim().length === 0){
<script src=""></script>
<input id="test" type="text" value = "5" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download