forms - jQuery check if input empty (0) on Submit -


<input type="text" readonly="" value="0" class="input-mini1 sum1">  <input type="text" readonly="" value="0" class="input-mini1 sum2"> <input type="text" readonly="" value="0" class="input-mini1 sum3"> <button type="button" id="btn_submit" class="btn">submit</button> 

solution tried:

$("#btn_submit").click(function(){     var isformvalid = true;      $(".input-mini1 input").each(function(){       if ($.trim($(this).val()).length == 0){          alertify.error("please check hours");          isformvalid = false;       }else{       alertify.error("valid hours");       }      });       if (!isformvalid) alert("please fill in required fields (indicated *)");     return isformvalid; }); 

for reason, when submit form empty/zero filled in, not validate. user must not submit form if input value 0 or 0.0 (either case) , should validated.

also when click on submit button, not loop through inputs.

any ideas how make work ?

your selector .input-mini1 input wrong, looking input elements descendants of element class input-mini1.

it should input.input-mini1 since input-mini1 class of input element

so

$("input.input-mini1").each(function () {     if ($.trim($(this).val()).length == 0) {         alertify.error("please check timesheet hours");         isformvalid = false;     } else {         alertify.error("valid timesheet hours");     } }); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -