javascript - How to make non editable text box to editable when i click on check box corresponding to it - Stack Overflow

There are one check box and a non editable text box corresponding to it. When I click on check box, cor

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 badges
Add a ment  | 

2 Answers 2

Reset to default 4

Basically:

$('#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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742398229a4436381.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信