Reputation: 231
I'm implementing any bulletin Free board pages applied Secret and non-secret by the board's page password number.
I want to implement if the checkbox that distinguish whether The writings are secret is checked, I want to remove readonly attribute of the password for applying the secret bulletin.
The password's id = bbs_password
the checkbox id = secret_yn
because of all source are my privacy, I can't attach it on this directly. Please understand me.
alternately, I attach a part of sourced codes by photo.
This is what I have so far :
$(document).ready(function(){
$('#bbs_password').attr('readonly','readonly')
if($('input:checkbox[id="secret_yn"]').is(":checked") == true){
$('#bbs_password').removeAttr('readonly','readonly');
if(document.bbs_write_form.bbs_password.value == ""){
alert("input the password!);
document.bbs_write_form.bbs_password.focus();
return false;
}
}
thanks very very much for reading this.
Upvotes: 1
Views: 9843
Reputation: 17075
To set element as read-only:
$('#bbs_password').prop('readonly', true);
And to switch it back to editable:
$('#bbs_password').prop('readonly', false);
If you have jQuery version older than 1.9, you need to use instead:
$('#bbs_password').attr('readonly', true);
Upvotes: 3
Reputation: 1845
Depend on your jQuery version try this:
$('.selector').prop('readonly', false);
Or
$('.selector').attr('readonly', false);
Upvotes: 0