Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi !
I want to get .SelectedIndex of DropDownList in .aspx Page.
I will use like below but not working.
C#
if(document.getElementById("<%=ddldocInge.ClientID%>").value==-1)
        {
          alert("Select the Doctor");
          document.getElementById("<%=ddldocInge.ClientID%>").focus();
          return false;
        }
Posted
Updated 2-Sep-11 1:38am
v2

You need to do something like ddldocInge.SelectedIndex in your script.
 
Share this answer
 
v2
Comments
Uday P.Singh 2-Sep-11 8:28am    
my 5!
Abhinav S 2-Sep-11 8:31am    
Thank you Uday.
Instead .value use .selectedIndex.
C#
if(document.getElementById("<%=ddldocInge.ClientID%>").selectedIndex == -1)
        {
          alert("Select the Doctor");
          document.getElementById("<%=ddldocInge.ClientID%>").focus();
          return false;
        }
 
Share this answer
 
Comments
LebneizTech 2-Sep-11 8:09am    
Sir, Not Working.
Toniyo Jackson 2-Sep-11 8:12am    
Are you calling the javascript from the button? Share the full code
LebneizTech 2-Sep-11 8:16am    
Yes,
All Condition is working except it.
<script language="javascript" type="text/javascript">
function IsValid()
{
//var isNum=/^(\".*\"|[A-Za-z]\w*)$/;^[a-zA-Z0-9]{1,11}$ \d+/2010
var IsID=/^[a-zA-Z0-9]{1,11}$/;
var ID=document.getElementById("<%=txtpatcode.ClientID%>").value;
var mach1=ID.match(IsID);
// var IsRN=\d+/2010;
// var RN=document.getElementById("<%=txtipdregno.ClientID%>").value;
// var matchRN=RN.match(IsRN);
if(mach1==null)
{
alert("Please Enter Valid Code");
document.getElementById("<%=txtpatcode.ClientID%>").focus();
return false;
}
if(document.getElementById("<%=txtfirnam.ClientID%>").value=="")
{
alert("Enter the Name");
document.getElementById("<%=txtfirnam.ClientID%>").focus();
return false;
}
if(document.getElementById("<%=ddldocInge.ClientID%>").SelectedIndex==-1)
{
alert("Enter the DR");
document.getElementById("<%=ddldocInge.ClientID%>").focus();
return false;
}
if(document.getElementById("<%=txtipdregno.ClientID%>").value=="")
{
alert("Can Not be Blank");
document.getElementById("<%=txtipdregno.ClientID%>").focus();
return false;
}
}
</script>
Toniyo Jackson 2-Sep-11 8:23am    
In selectedIndex, s should be small letter and I should be capital letter.
Uday P.Singh 2-Sep-11 8:28am    
my 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900