how to save data by disabled text box?

2019-08-21 23:44发布

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.

1条回答
放我归山
2楼-- · 2019-08-22 00:39

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);
    }       
}
查看更多
登录 后发表回答