SO - 22607474

by Petar Pilipovic

HTML

<input class="zx" type="text" name='customer[channels]' value="23" max="46" min="1"/><button class="cncl">X</button>

JavaScript

$('.cncl').click(function(){
    $(this).prev().val(function(){
        return this.defaultValue;
    })
})

$("[name='customer[channels]']").on('blur', function (e) {
  val = e.target.value;
  maxVal = e.target.getAttribute('max');
  console.log(val);
  console.log(maxVal)
  if (val > maxVal) {
    $('#authiorizaChange').attr('disabled', true) && alert("Value must be less then or equal to " + maxVal);
  } else {
    $('#authiorizaChange').removeAttr('disabled');
  }
})