Form submits when input is null
I want to prevent form submission when there is no input in the text boxes but the form submits even when the input is empty. How do I fix this?
- var input = $("#zip").val();
- var input1 = $("#phone").val();
- if ( $.trim(input).length == 0 || $.trim(input1).length == 0 ){
- event.preventDefault();
- }
- <input type="text" size="30" id="zip" name="zip"><br />
- <input type="text" size="30" id="phone" name="phone">