Form submits when input is null

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?

  1. var input = $("#zip").val();
  2. var input1 = $("#phone").val();

  3. if ( $.trim(input).length == 0 || $.trim(input1).length == 0 ){
  4. event.preventDefault();
  5. }


  1. <input type="text" size="30" id="zip" name="zip"><br />
  2. <input type="text" size="30" id="phone" name="phone">