html - Atleast one select box is required -


i have 2 select boxes in want @ least 1 should required. if select 1 select box should tru. if select both select box should tru. if not select 1 should required .

here code

<select name="a[]" >    <option value="volvo">volvo</option>    <option value="saab">saab</option>    <option value="mercedes">mercedes</option>    <option value="audi">audi</option>  </select>    <select name="b[]" >    <option value="volvo">volvo</option>    <option value="saab">saab</option>    <option value="mercedes">mercedes</option>    <option value="audi">audi</option>  </select>

html :

<select name="a[]" id="test1" >   <option value="">select vehicle</option>   <option value="volvo">volvo</option>   <option value="saab">saab</option>   <option value="mercedes">mercedes</option>   <option value="audi">audi</option> </select>  <select name="b[]" id="test2" >   <option value="">select vehicle</option>   <option value="volvo">volvo</option>   <option value="saab">saab</option>   <option value="mercedes">mercedes</option>   <option value="audi">audi</option> </select> 

javascript :

    if($('#test1').val() == "" && $('#test2').val() == "") {         alert("atleast select 1 vehicle");     }      $('#test1').on('change', function() {         if($('#test1').val() == "" && $('#test2').val() == "") {             alert("atleast select 1 vehicle");         }     })      $('#test2').on('change', function() {         if($('#test1').val() == "" && $('#test2').val() == "") {             alert("atleast select 1 vehicle");         }     }) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -