Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Flowing Dropdown Validation Not work( tabbing or by moving the cursor)?? what is the error.anyone plz help me??data bound this dropdown.



C#
function LoseFocus(ddlElem) {

         ddlElem.blur();
         var val = ddlElem.options[e.selectedIndex].value;
         if (val == "" || val == "Select")
             alert('Error');

     }

--------------------------------------------------------------------------------------------


XML
<asp:DropDownList ID="DropDownCountry" runat="server" AutoPostBack="true"
                      CssClass="input" Height="20px"
                      onselectedindexchanged="DropDownCountry_SelectedIndexChanged" TabIndex="18"
                      Width="99%"  onchange="LoseFocus(this);" >
                  </asp:DropDownList>

----------------------------------------------------------------------------------------------

DropDownCountry.Attributes.Add("onchange", "LoseFocus(this)");
Posted
Comments
S R JHALA 28-Feb-13 0:56am    
When you want to validate, when user changes the value of DDL or on submitting the form ?

1 solution

First importtant thing to notice is your registering event onchage twice i
Here
DropDownCountry.Attributes.Add("onchange", "LoseFocus(this)");
and
onchange="LoseFocus(this);" in aspx

from your code what i understand is on dropdown lost focus you want validate dropdown please do it below for same
onblur="LoseFocus(this);" make onblur instead of onchage. and below is update javascript method

function LoseFocus(ddlElem) {

ddlElem.blur();
var val = ddlElem.options[ddlElem.selectedIndex].value;
if (val == "" || val == "Select")
alert('Error');

}


Please let me know if you need more help
 
Share this answer
 
Comments
[no name] 28-Feb-13 1:17am    
Tnx a lot dear..

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