0

How will i disable textbox2 if the textbox 1 is equal to true. it's not inputted value its set value.

$('#valuetags').ready(function() {
  if ($(this).val() == 'true') {
    $('#quantitytotransfer').prop('disabled', true);
  } else {
    $('#quantitytotransfer').prop('disabled', false);
  }
)};
<input name="valuetags" type="text" value="true" class="form-control" id="valuetags"> 

<input type="number"  required class="form-control" name="quantitytotransfer" id="quantitytotransfer" maxlength="11">
Mosh Feu
  • 28,354
  • 16
  • 88
  • 135

3 Answers3

1

You can't use ready for element. Only for the document.

$(function(){
  if ($('#valuetags').val() == 'true') {
    $('#quantitytotransfer').prop('disabled', true);
  } else {
    $('#quantitytotransfer').prop('disabled', false);
  }
});
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<input name="valuetags" type="text" value="true" class="form-control" id="valuetags"> 

<input type="number"  required class="form-control" name="quantitytotransfer" id="quantitytotransfer" maxlength="11">

Here is a great answer about this issue.

By the way You can short your code by pass the condition as the variable to prop function:

$(function(){
    $('#quantitytotransfer').prop('disabled', $('#valuetags').val() == 'true');
});
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<input name="valuetags" type="text" value="true" class="form-control" id="valuetags"> 

<input type="number"  required class="form-control" name="quantitytotransfer" id="quantitytotransfer" maxlength="11">
Community
  • 1
  • 1
Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
0

When you input text to valuetags it's value attribute is overwritten with the user's input value, i.e. value="true" is no longer set.

Try adding a different attribute in the html such as data-value="true" then

if ($(this).data("value") == 'true'){}
grateful
  • 1,128
  • 13
  • 25
0
        function activer(){
          if ($('#valuetags').val() == 'true') {
            $('#quantitytotransfer').prop('disabled', true);
          } else {
            $('#quantitytotransfer').prop('disabled', false);
            ;
          }
        }
        $( document ).ready(function() {
            activer();
            $('#valuetags').on('change', function() {
              activer();
            });
        });
pheaselegen
  • 398
  • 1
  • 4
  • 15