I have piece of html code as well as script code. I need solution to handle on change event of one text box that disable act of inputting data in another text field. Could any one help me in regarding.
<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();
});
});
You can use $(":disabled") to select all disabled items in the current context. To determine whether a single item is disabled you can use $("#textbox1").is(":disabled") . Save this answer.
Disable the TextBox by adding the e-disabled to the input parent element and set disabled attribute to the input element.
To make a textarea and input type read only, use the attr() method .
To remove disabled attribute using jQuery, use the removeAttr() method. You need to first remove the property using the prop() method. It will set the underlying Boolean value to false.
For one you were missing #
on 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();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With