2 Replies - 319 Views - Last Post: 25 November 2016 - 08:58 AM

#1 makamo66  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 92
  • Joined: 04-February 09

Form submits when input is null

Posted 25 November 2016 - 08:45 AM

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?

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


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

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



Is This A Good Question/Topic? 0
  • +

Replies To: Form submits when input is null

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4125
  • View blog
  • Posts: 13,016
  • Joined: 08-June 10

Re: Form submits when input is null

Posted 25 November 2016 - 08:47 AM

<input type="text" size="30" id="zip" required name="zip">

Was This Post Helpful? 0
  • +
  • -

#3 makamo66  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 92
  • Joined: 04-February 09

Re: Form submits when input is null

Posted 25 November 2016 - 08:58 AM

<button type="submit" class="btn btn-success">Continue</button>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1