1

In my jsp page, 1 checkbox, 2 textbox and 1 submit button. The checkbox is used for enabling and disabling the text box. Data saved when textbox is enable but not saved when textbox is disable.

following code is for toggle.

function toggleFields(status){
    if (status==false){
        $("#textbox1").removeAttr("disabled");
        $("#textbox2").removeAttr("disabled");
        } 
        else {
        $("#textbox1").attr("disabled", "disabled");
        $("#textbox2").attr("disabled", "disabled");
    }       
}

please help me in this.

  • Have you tried getting the values of textbox with `$("#textbox1").val()`? – Dhaval Marthak Jul 24 '13 at 08:57
  • Do not just focus on the text box behavior if it was disabled or enabled, just validate the check box, if the check box was check then it will be saved otherwise not. – HTTP Jul 24 '13 at 09:00
  • @Nesmar, yes when checkbox is checked then it will be saved otherwise not. what to do now? – Jitendra Khedar Jul 24 '13 at 09:05
  • @JitendraKhedar That answers your problem, I mean if the checkbox returns true then it will execute your code to save the data otherwise it will do nothing even how many clicks on the submit button. Get It? – HTTP Jul 24 '13 at 09:10
  • @Nesmar, ok get it, can u give me solution ??? – Jitendra Khedar Jul 24 '13 at 09:20

1 Answers1

1

You can use readonly instead of disabled.

 $("#textbox1").attr("readonly", true);

Your code would be

function toggleFields(status){
    if (status==false){
        $("#textbox1").attr("readonly", false);
        $("#textbox2").attr("readonly", false);
        } 
        else {
        $("#textbox1").attr("readonly", true);
        $("#textbox2").attr("readonly", true);
    }       
}
Adil
  • 146,340
  • 25
  • 209
  • 204