2

I want to disable specific input, when adding any text to another input. What tried doing is this JS

$('#sPriceRewards').on('input', function() {
$(this).find('.inputReward').not(this).prop('disabled', this.value.length)});

HTML

<input type="text" name="sPriceRewards" id="sPriceRewards" value="" />
<input type="text" name="sReward1" value="" class="inputReward" />

Here's fiddle

Tnx

4 Answers 4

4

Here is a simple logic: https://jsfiddle.net/p623brhL/4/

$('#sPriceRewards').on('input', function() {

   if($(this).val().length)
      $('.inputReward').prop('disabled', true);
   else
      $('.inputReward').prop('disabled', false);
});
Sign up to request clarification or add additional context in comments.

Comments

2

You need to modify the selector to target next element:

 $('#sPriceRewards').on('input', function() {
   $(this).next().prop('disabled', this.value.length);
 });

Working Demo

Comments

0

http://jsfiddle.net/p623brhL/3/ now works. You tried to find another input IN current one. But it is not child of current input

$('.inputReward').not(this).prop('disabled', this.value.length)});

Comments

0
$('#sPriceRewards').on('change', function() {
    if(this.value.length > 0)
        $(this).siblings('.inputReward').attr('disabled','disabled');
    else
        $(this).siblings('.inputReward').removeAttr('disabled');
});

1 Comment

Please include some explanation of how this work or what you've fixed, rather than just code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.