Hi, I have a the below select box: <form name="test" method="post"> <select name="myoptions[]" multiple> <option value="IN">India</option> <option value="US">United States</option> <option value="UK">United Kingdom</option> <option value="PK">Pakistan</option> </select><BR> <input type="submit" value="show" onClick="docheck();"> </form> HTML: If a user do not select at least one option, we should raise an alert message?, Can anyone help me on this? thanks in advance tamilsoft
if(document.test.elements['myoptions[]'].selectedIndex==-1){ alert("Please select atleast one type.");
Hello, Write down following javascript in head part function check(b) { for (var c=0,d=0,e; e=b[d]; d++) { if (e.type=='select-multiple' && e.name.match(/^myoptions\[\]$/) && e.selectedIndex >= 0 ) c++; } if(c==0) { alert("Select at least one"); return false; } return true; } You have to call this function like following <form name='frm1' action='#' method="post" onsubmit="return check(this);"> .... your code here.... </form>