Reputation: 1893
can any one tell me what is option for readonly for checkbox because I want to submit the value for the checkbox and at the same time want to achive the functionality of disable the attribute but using disable does not submit the value and I think readonly is not working in checkbox.
Please help me.
Upvotes: 0
Views: 747
Reputation: 646
You can try something like this
<form action = "your url here" method = "POST">
NonEditableValue<input type = "checkbox"/ id = "mycheckbox" value = "ValueIwantChecked">
<input type = "submit" id = "somebutton" value = "Get CheckBox Value" />
</form>
Javascript
$("#somebutton").click(function(e){
var ischecked = $('#mycheckbox').attr('checked')?true:false;
if(!ischecked){
e.preventDefault();
alert("Please select value");
}
else{
$("#mycheckbox").attr("disabled","true");
alert($("#mycheckbox").val());
}
});
This will disable the checkbox on submit and the alert in the "else" of javascript gives the value of the check box.Thus the value is preserved.
Hope this helps ..
Upvotes: 1
Reputation: 3508
try this one
<input name="chkbox1" type=checkbox readonly>check box 1</input>
Upvotes: 0
Reputation: 12693
WHen you want to disable the click Just return false:
<input type="checkbox" onclick="return false"/>
This will make sure that you can't change the value of the checkbox
Upvotes: 0