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
Post a Comment