Click here to Skip to main content
16,004,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI ,

I have scenario like

Dropdownbox name Sex data- female,male
Textbox maternitydays- if user choose female then this Textbox must be mandatory

if the choose in male option then textbox disabled

CAn anyone give idea how to do this in MVC3 using jQuery
Am completely new to MVC3 and jQuery

please help me anyone

Thanks
Posted

1 solution

Dear kimberly,

Please use following code

C#
$("#drpSex").change(function()
{
         if(this.value== 'female')
            $('#txtMaternityDays').removeAttr("disabled"); 
         else 
            $('#txtMaternityDays').attr("disabled", "disabled");
}
//UPDATED
$(document).ready(function() {
   jQuery("#txtMaternityDays").blur(function() {
      if(this.val() == "")
      { 
          alert("You must need to fill Maternity Days");
          this.focus();
      }  
   });
 });


Thanks,
Imdadhusen
 
Share this answer
 
v3
Comments
kimberly wind 1-Jun-12 7:38am    
hey thanks dear great help my 5!
kimberly wind 1-Jun-12 7:59am    
again i want to show message since they selected female once they cross this txtMaternityDays need to show alert like 'You must need to fill this' like this i wants to pop alert
Sunasara Imdadhusen 1-Jun-12 8:54am    
Thanks for your appreciations, i have updated code as per your requirements.
kimberly wind 5-Jun-12 2:47am    
thanks you so much

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