Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Code is shown below:

C#
<script language="javascript" type="text/javascript">
 function validateFrm(){
var frm=document.forms["frm"]

if(trim(frm.txtEmailId.value)==""){
alert('Enter Email')
frm.txtEmailId.focus()
return false}

else if(trim(frm.txtPassword.value)==""){
alert('Enter Password')
frm.txtPassword.focus()
return false}


else if(trim(frm.ddlCreatePro.value)=="0"){
alert('Select Create Profile For')
frm.ddlCreatePro.focus()
return false}


else if(trim(frm.txtFirstName.value)==""){
alert('Enter First Name')
frm.txtFirstName.focus()
return false}

else if ( ( frm.rbtMale.checked == false ) && ( frm.rbtnFemale.checked == false ) )
 {
 alert ( " choose your Gender" )
 return false}

else if(trim(frm.ddlDD.value)=="0"){
alert('Select Date')
frm.ddlDD.focus()
return false}

else if(trim(frm.ddlMM.value)=="0"){
alert('Select Month')
frm.ctl00_ddlMM.focus()
return false}

else if(trim(frm.ddlYYYY.value)=="0"){
alert('Select Year')
frm.ddlYYYY.focus()
return false}

else if(trim(frm.ddlState.value)=="0"){
alert('Select State')
frm.ddlState.focus()
return false}

else if(trim(frm.ddlCity.value)=="0"){
alert('Select City')
frm.ctl00_cphBody_ddlCity.focus()
return false}

else if(trim(frm.txtMobileNo.value)==""){
alert('Enter Mobile')
frm.txtMobileNo.focus()
return false}

else if(trim(frm.ddlMaritalStatus.value)=="0"){
alert('Select Material Status')
frm.ddlMaritalStatus.focus()
return false}

else if(trim(frm.ddlReligion.value)=="0"){
alert('Select Religion')
frm.ddlReligion.focus()
return false}

else if(trim(frm.ddlCaste.value)=="0"){
alert('Select Caste')
frm.ddlCaste.focus()
return false}
 }
    </script>


i am calling this in save btn onclientclick :
VB
<asp:ImageButton ID="imgSave" runat="server" CssClass="btn1" AlternateText="Save"
                                    OnClick="imgSave_Click" OnClientClick="return validateFrm()" Style="height: 16px" />




Problem here is the validation is working till two fields. it is not working from ddlCreatePro field on words which is drop down.

Please let me know what is my mistake in the above code...
Posted
Comments
Sergey Alexandrovich Kryukov 14-Mar-12 1:56am    
Did you try to run it under JavaScript debugger? Usually finding a bug is pretty straightforward.
--SA

Use it
SQL
else if(frm.ddlCreatePro.selectedIndex==0){
alert('Select Create Profile For')
frm.ddlCreatePro.focus()
return false}
 
Share this answer
 
Comments
Rajesh Yerramsetti 14-Mar-12 2:00am    
i have tried with selected index also but it is not working....
I cannot see a bug right now, but note that you did not show the complete page content. If can be a problem. Really, use JavaScript.

My first guess is this: during validation, an exception is thrown after the validation of some first fields. There can be different problems, such as field name mismatch (again, I cannot see you complete page). Usually, if you run it not under debugger and/or the JavaScript debugger is not enabled (which is a usual problem), you might not have noticed that. Usually, HTTP servers working in production modes do not reveal unhandled JavaScript exceptions. So, you can also catch all exceptions around this method and show detailed exception information. This way, you can find and fix the problem in no time.

—SA
 
Share this answer
 
Hi, You can use above code or use below code:

JavaScript
else if(frm.ddlCreatePro.options[frm.ddlCreatePro.selectedIndex].value=="0"){
alert('Select Create Profile For')
frm.ddlCreatePro.focus()
return false}
 
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