Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - java script to validate combobox

 
Thread Tools Search this Thread
Old 05-05-2007, 12:07 AM   #1
Default java script to validate combobox


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
  Reply With Quote
Old 05-05-2007, 01:57 AM   #2
Scott M.
 
Posts: n/a
Default Re: java script to validate combobox
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.
  Reply With Quote
Old 05-05-2007, 08:52 AM   #3
Mark Rae
 
Posts: n/a
Default Re: java script to validate combobox
<> 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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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