There are one check box and a non editable text box corresponding to it. When I click on check box, corresponding non editable text box should bee an editable text box. How can I achieve this?
There are one check box and a non editable text box corresponding to it. When I click on check box, corresponding non editable text box should bee an editable text box. How can I achieve this?
Share Improve this question edited Jul 30, 2012 at 11:44 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked Jul 30, 2012 at 5:37 rajraj 592 silver badges9 bronze badges2 Answers
Reset to default 4Basically:
$('#some-checkbox').click(function() {
$('#some-textfield').prop('disabled', !$(this).is(':checked'));
});
Now, how you go about finding the corresponding text box depends on your markup. One way could be to give the text box a class that is the ID of the checkbox. Applying that to all checkboxes might look something like this:
$(':checkbox').click(function() {
var box = $(this);
$('.' + box.attr('id')).prop('disabled', !box.is(':checked'));
});
Otherwise, the text field may be located by its position on the DOM:
<div class="wrapper">
<input type="checkbox">
...
<div>
<input type="text" disabled="disabled" />
</div>
</div>
You might then do something like:
$(':checkbox').click(function() {
var box = $(this);
box.closest('.wrapper').find('input[type=text]').prop('disabled', !box.is(':checked'));
});
This code actually works fine, and ready to use.
This is the form stuff:
<form id="myGame" name="myGame" action="" method="post">
<input type="radio" name="checkme" id="checkme" onClick="openTheHouse();" >Open Sesame
<input name="open_id" id="openid" type=text disabled="disabled">
</from>
And the Script: its pretty cool actually, nothing plicated in this script.
<script type="text/javascript">
function openTheHouse()
{
if(document.myGame.checkme.checked == true)
{
document.myGame.openid.disabled = false ;
}
}
</script>
thats it, all done. Certainly i believe it works.