jQuery Conditional Form Validation -



jQuery Conditional Form Validation -

i've been looking around stackoverflow , few other sites assistance on conditional validation of form fields. of questions related checkboxes, mine issue around select field.

i have deployed jquery , jqueryui , working correctly on front. haven't installed jquery validate think can achieved without it, happy told otherwise. here problem:

if user selects "open", "dateopened" field needs required. if select "closed" "dateclosed" required.

<form action="" method="post"> <select name="select12" id="select12"> <option>select...</option> <option value="1">open</option> <option value="2">closed</option> </select> <input name="dateopened" id="dateopened" type="text" /> <input name="dateclosed" id="dateclosed" type="text" /> <input name="submit" type="submit" value="update"/> </form>

can advise best solution?

thanks nick

here code, hope helps -

<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(document).ready(function(){ $( "#update" ).click(function() { var abc = $( "#select12" ).val(); if ( abc == "1" ) { var open = $("#dateopened").val(); alert(open); } else { var close = $("#dateclosed").val(); alert(close); } }); }); </script> </head> <body> <select name="select12" id="select12"> <option>select...</option> <option value="1">open</option> <option value="2">closed</option> </select> <input name="dateopened" id="dateopened" type="text" /> <input name="dateclosed" id="dateclosed" type="text" /> <input name="submit" type="submit" id="update" value="update"/> </form> </body> </html>

jquery validation

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -