Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have field like this

Student Marks

C++ [checkbox] textboxfor

so initially textbox should be disable but when i the checkbox is checked it should get enable...
can anyone give a hint?
Posted
Comments
[no name] 28-Feb-14 23:36pm    
how is about to implement the OnCheckboxClick and there you write something like:
MyTextField->Enabled= MyCheckBox->Checked

1 solution

Please try is as below.

HTML

XML
<input type="checkbox" name="marks" id="marks" />
<input type="text" name="studentMarks" id="studentMarks">



JS

C#
$(document).ready(function() {

  $("#studentMarks").attr('disabled','disabled');

  $("#marks").change(function(){
      if ($(this).is(':checked')) {
          $("#studentMarks").removeAttr('disabled');
      }
  });
});


LIVE DEMO : JSFiddle
 
Share this answer
 
Comments
Member 10559568 1-Mar-14 7:11am    
Thank you very much..it works...
Sampath Lokuge 1-Mar-14 7:17am    
Glad to hear that it helped! :)
Member 10559568 1-Mar-14 7:14am    
if someone want to disable textbox again after uncheck...below is modified code..
$(document).ready(function() {

$("#studentMarks").attr('disabled','disabled');

$("#marks").change(function(){
if ($(this).is(':checked')) {
$("#studentMarks").removeAttr('disabled');
}
if ($(this).is(':unchecked')) {
$("#studentMarks").attr('disabled','disabled');
}

});
});
venkatpvc 2-Apr-14 20:25pm    
thank you
Sampath Lokuge 3-Apr-14 1:52am    
You're warmly welcome. :)

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