Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
if (document.getElementById("<%=DropDownList6.ClientID%>").value == "0")
         {
        alert("Please fill the Event Starting Time");
          document.getElementById("<%=DropDownList6.ClientID%>").focus();
          return false;
                         }



this is the code...but its not working can any 1 tell me whats the problem with this code...
Posted
Updated 2-Sep-12 19:37pm
v2
Comments
dimpledevani 3-Sep-12 1:43am    
where have you written this code?? I mean the event??

Try this:
JavaScript
function fnValidate()
{
    if(document.getElementById('<%=ddlTest.ClientID%>').selectedIndex == 0)
    {
        alert("Please select from drop down");
        return false;
    }
    return true;
}


--Amit
 
Share this answer
 
Comments
Mohamed Mitwalli 3-Sep-12 2:53am    
5+
_Amy 3-Sep-12 3:07am    
Thanks Mohamed. :)
Hi ,
You could also try this one
XML
<div>
<asp:Button ID="Button2" runat="server" Text="Button" ValidationGroup="ss" />
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
    ValidationGroup="ss">
<asp:ListItem Text="---select---" Value="0" ></asp:ListItem>
<asp:ListItem Text="---test---" Value="1" ></asp:ListItem>

</asp:DropDownList>
<asp:CompareValidator ID="CompareValidator1" runat="server"
    ControlToValidate="DropDownList1" Display="Dynamic"
    ErrorMessage="CompareValidator" ForeColor="#FF3300" Operator="GreaterThan"
    SetFocusOnError="True" ValueToCompare="0" ValidationGroup="ss"></asp:CompareValidator>
    </div>

Best Regards
M.Mitwalli
 
Share this answer
 
Can I suggest an Alternative?

Why not try RequiredFieldValidator? Provide an empty value for the first element and direct your validator to the Dropdownlist6.
 
Share this answer
 

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