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();
});
});
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();
});
});
Share
Improve this question
edited Dec 18, 2013 at 18:01
Jason P
27k3 gold badges32 silver badges45 bronze badges
asked Dec 18, 2013 at 17:58
PallaviPallavi
3131 gold badge4 silver badges17 bronze badges
5
|
3 Answers
Reset to default 10For 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();
});
});
$("#ccit").attr('disabled','disabled');
You can also use attr
on the line $("ccit").attr('disabled',true);
if prop
gives you an error
<ccit></ccit>
element ? – adeneo Commented Dec 18, 2013 at 18:00$("#ccit")
, hence my first comment – adeneo Commented Dec 18, 2013 at 18:02event.returnValue is deprecated. please use the standard event.preventDefault() instead
is just a warning on an old version of jQuery but it is not the reason your code is not working.. Javascript is a client side language so I don't understand what you mean by its not working server side. Sorry I don't know how to help you at this point unless you can demonstrate exactly what is not working. – Trevor Commented Dec 19, 2013 at 13:46Update 2
that is the last thing I can think of. – Trevor Commented Dec 19, 2013 at 16:16