How to make a text box on and off when changing using jQuery

I have html code as well as script code. I need a solution to handle the event of a change in one text field that disables the action of entering data into another text field. Can anyone help me with a review.

<div id="cca" class="leaf">
 <label class="control input text" title="">
    <span class="wrap">cca</span>
     <input class="" type="text" value="[Null]"/>
    <span class="warning"></span>
 </label>
</div>
<div id="ccit" class="leaf">
 <label class="control input text" title="">
    <span class="wrap">ccit</span>
     <input class="" type="text" value="[Null]"/>
    <span class="warning"></span>
 </label>
</div>

$(document).ready(function () {        
    alert("hello");        
    $("#cca").on('change', 'label.control input', function (event) {
        alert('I am pretty sure the text box changed');
        $("ccit").prop('disabled',true);
        event.preventDefault();
    });
});
+4
source share
2 answers

For one you were absent #from your$("ccit")

$(document).ready(function () {        
    alert("hello");        
    $("#cca").change(function(){
        alert('I am pretty sure the text box changed');
        $("#ccit").prop('disabled',true);
        event.preventDefault();
    });
});

http://jsfiddle.net/qS4RE/

Update

$(document).ready(function () {               
    $("#cca").on('change', 'label.control input', function (event) {
        alert('I am pretty sure the text box changed');
        $("#ccit").find('label.control input').prop('disabled',true);
        event.preventDefault();
    });
});

http://jsfiddle.net/qS4RE/1/

Update 2

$(document).ready(function () {               
    $(document).on('change', '#cca label.control input', function (event) {
        alert('I am pretty sure the text box changed');
        $("#ccit").find('label.control input').prop('disabled',true);
        event.preventDefault();
    });
});
+9
source

You can also use attrin line$("ccit").attr('disabled',true);

if it propgives an error message

0
source

All Articles