javascript - Drop down menu Validation on button press w/ Alert -


the user should select 1 of options in drop down menu before proceeding form. "next button" should send alert if no option selected. both yes , no should allow next button work. need javascript this.

here html:

<fieldset>  		<h2 class="fs-title">past history </h2>  		<h3 class="fs-subtitle">please select 1 of following</h3>          <div>  <select name="past" id="past">    <option value=""disabled selected>select one</option>    <option value="a">yes</option>    <option value="b">no</option>  </select>           </div>          <br>   		<input type="button" name="previous" class="previous action-button" value="previous" />  		<input type="button" name="next" class="next action-button" id="nextpast" value="next" />  	</fieldset>

this 1 works fine , won't let user continue unless have selected option

function alertbox() {      if($("#past option:selected").text() == "select one"){      alert("you must select option!");    }  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <fieldset>  		<h2 class="fs-title">past history </h2>  		<h3 class="fs-subtitle">please select 1 of following</h3>          <div>  <select name="past" id="past">    <option value=""disabled selected>select one</option>    <option value="a">yes</option>    <option value="b">no</option>  </select>           </div>          <br>   		<input type="button" name="previous" class="previous action-button" value="previous" />  		<input type="button" onclick="alertbox()" name="next" id="next" class="next action-button" id="nextpast" value="next" />  	</fieldset>


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -