Javascript validation:multiple select box-drop down box validation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<html> <head> <title>VALIDATION JAVASCRIPT:Select box validation using javascript</title> <script type="text/javascript"> function validate() { var countries=document.getElementById("country"); var countries_count=countries.options.length; if(countries_count==5) { alert("You entered five countries"); return false; } } </script> </head> <body> <form method="post" id="form1" name="form1"> <div> <table> <tr> <td > <span>List of Countries</span><br> </td> </tr> <tr> <td> <select multiple size="25" name="country" id="country" style="width:250px;";> <option value="India">India</option> <option value="pakisthan">Pakisthan</option> <option value="sreelanka">Sreelanka</option> <option value="japan">Japan</option> <option value="usa">USA</option> </select> </td> </tr> </table> </div> <table> <tr> <td> <input accesskey="l" onclick="return validate();" value="Submit" name="mysubmit" id="mysubmit" type="submit"> </td> </tr> </table> </form> </body> </html> |