![]() |
|
|
|||||||
![]() |
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; > } > Scott M. |
|
|
|
#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 Mark Rae |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to execute an external software from VHDL? And how to interface VHDL with JAVA? | becool_nikks | Software | 0 | 03-06-2009 07:08 PM |
| Live projects on C, C++, Java, .NET for final year students | sheetal7853@gmail.com | Software | 0 | 10-05-2008 04:20 AM |
| Java with Asp.net | mdinant | Software | 0 | 04-04-2008 12:21 PM |
| Java Beginners | Still Bill | Software | 3 | 02-19-2008 10:13 AM |
| help with master page and java script | alain23 | Software | 0 | 09-20-2007 06:02 AM |