473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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;
}
May 4 '07 #1
2 2518
acoder
16,027 Expert Mod 8TB
I assume the user is not allowed to select the first item in the list.

You can use the selectedIndex property. Check if it's 0. If it is, that means the first item is selected.
May 5 '07 #2
pbmods
5,821 Expert 4TB
You can check the selected index of a select by using:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('theElement').selectedIndex
  2.  
You can check the value of the selected option by using:

Expand|Select|Wrap|Line Numbers
  1. var theElement = document.getElementById('theElement');
  2. theElement.options[theElement.selectedIndex].value
  3.  
http://www.w3schools.com/htmldom/dom_obj_select.asp
http://www.w3schools.com/htmldom/dom_obj_option.asp
May 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: NNTP | last post by:
#!/usr/bin/perl use Validate::Net; if ( Validate::Net->ip($ARGV)) { print "valid"; exit 0; } print "invalid"; #--done
3
by: hoz | last post by:
Hi , I am developing an web application . I have a form for user login ,contains two textboxs . How can i check them if these are empty using client side validation ? But i want it like below...
1
by: bobby421 | last post by:
Hi, I have a master page and content page. In content page I have to validate the text boxes for name,address, phone number and email address etc. But as content pages doersn't have html section...
2
by: bbawa1 | last post by:
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....
1
by: Vinodsrvk | last post by:
I am calling one validation function from the java script, that validation function will validate all the controls and return true/ false in the calling function I would like to check the return...
2
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
2
by: poornimanithya76 | last post by:
Hi, I am having grid view an my page which is having template fields(text box, check box and drop down).If user clicks on check box i need to consider text box and drop down as a required fields.i...
1
by: menyki | last post by:
am still finding it difficult as a new java user. am designing a software that has multiple forms, controls such as combobox and so on and finding it difficult to do the following. i want some...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.