![]() |
|
|
|||||||
![]() |
ASP Net - java script to validate combobox |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
have to validate my web page using java script. I have one dropdown
list also . I need a javascript to validate weather any item in dropdownlist is selected or not. e.g ddlDrop is my dropdownlist. To validate other controls I am using following function validate() { if (document.getElementById("<%=txtUserName.ClientID% >").value=="") { alert("Please Pprovide UserName"); document.getElementById("<%=txtUserName.ClientID%> ").focus(); return false; } if (document.getElementById("<%=txtPassword.ClientID% >").value=="") { alert("Please provide Password"); document.getElementById("<%=txtPassword.ClientID%> ").focus(); return false; } bbawa1@yahoo.com |
|
|
|
|
#2 |
|
Posts: n/a
|
A drop down list must always have something selected, so usually you make
the first item in the list say something like --- Please Choose From Below --- and then check to see if the first item is still selected at the time of submission: if(ddlDrop.selectedIndex == 0) { //No item was selected } else { //Something other than item 1 was selected } Also, in your other code (below), there is no need to refer to your controls via: document.getElementById("<%=txtUserName.ClientID%> ").value just write: txtUserName.value -Scott <> wrote in message news: oups.com... > have to validate my web page using java script. I have one dropdown > list also . I need a javascript to validate weather any item in > dropdownlist is selected or not. e.g ddlDrop is my dropdownlist. > > To validate other controls I am using following > function validate() > { > if (document.getElementById("<%=txtUserName.ClientID% >").value=="") > { > alert("Please Pprovide UserName"); > document.getElementById("<%=txtUserName.ClientID%> ").focus(); > return false; > } > if (document.getElementById("<%=txtPassword.ClientID% >").value=="") > { > alert("Please provide Password"); > document.getElementById("<%=txtPassword.ClientID%> ").focus(); > return false; > } > |
|
|
|
#3 |
|
Posts: n/a
|
<> wrote in message
news: oups.com... > have to validate my web page using java script. I have one dropdown > list also . I need a javascript to validate weather any item in > dropdownlist is selected or not. e.g ddlDrop is my dropdownlist. Assuming you have a blank option as the first option in the DropDownList: if(document.getElementById('<%=ddlDrop.ClientID%>' ).selectedIndex == 0) { alert("Please Pprovide DropDown"); document.getElementById("<%=ddlDrop.ClientID%>").f ocus(); return false; } -- http://www.markrae.net |
|