[Solved] html javascript set max of input field according to option


updateTextfield = function(obj){
  $('#price').attr('max-value', $($(obj).find('option:selected')[0]).attr('av'))
  CheckMaxValue(document.getElementById('price'))
 }
 
 CheckMaxValue = function(obj){
  if(parseInt(obj.value) > parseInt(obj.getAttribute('max-value'))){
    obj.value = obj.getAttribute('max-value')
  }
 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select required class="bg-mega" id="size" name="size" style="height: 30px; width: 100px; border: 0px;" onchange="updateTextfield(this)">
          <option value="">Select</option>
          <option value="S" title="25 available!" av="25">Small</option>
          <option value="N" title="15 available!" av="15">Normal</option>
          <option value="L" title="10 available!" av="10">Large</option>
          <option value="XL" title="20 available!" av="20">extra Large</option>          
      </select>
      
      <input type="number" name="price-quanti" id="price"  placeholder="Select Quantity" style="height: 30px; width: 100px;" max="should change according to size"  min="1" required onkeyup="CheckMaxValue(this)">

Any question don’t hesitate on asking

0

solved html javascript set max of input field according to option