javascript - jQuery Validate: how do I validate based on other field's value? -


i have form. if select field set first option, have 2 radio groups must set. if select set other value, don't have set.

the select:

<div class="field grid_10">     <label for="severityid" class="grid_3">severity</label>     <div class="grid_6">          <form:select id="severityid" path="severityid" items="${severitylist}" itemvalue="id" itemlabel="title" />     </div>     <div class="clear"> </div> </div> 

the validation:

 function validate_eventreviewform() {            jquery('#review-edit-form').validate ({         rules: {             samplewaslost: {required: {                 depends: function(element){                     return $("#severityid").val() == 1                 }}},             backupsampleavail: {                 depends: function(element){                     return $("#severityid").val() == 1                 }}         }     }); } 

as can see, tried 2 separate ways jquery mark required. neither 1 works.

what doing wrong? how make work?

the problem second script causing error causing validation fail

jquery(function($) {    $('#review-edit-form').validate({      rules: {        samplewaslost: {          required: {            depends: function(element) {              return $("#severityid").val() == 1            }          }        },        backupsampleavail: {          required: {            depends: function(element) {              return $("#severityid").val() == 1            }          }        }      }    });  });
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.js"></script>  <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.js"></script>  <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/additional-methods.js"></script>      <form id="review-edit-form" method="post" action="">    <select name="severityid" id="severityid">      <option></option>      <option>1</option>      <option>2</option>    </select>    <br />    <input type="radio" name="samplewaslost" value="1" />    <input type="radio" name="samplewaslost" value="2" />    <input type="radio" name="samplewaslost" value="3" />    <input type="radio" name="samplewaslost" value="4" />    <br />    <input type="radio" name="backupsampleavail" value="1" />    <input type="radio" name="backupsampleavail" value="2" />    <input type="radio" name="backupsampleavail" value="3" />    <input type="radio" name="backupsampleavail" value="4" />    <input type="submit" value="save" />  </form>


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -