0

Im testing the dynamic changes of ID from dynamically added input fields. price0 ID works but price1 doesnt work. how to fix this?

$(document).ready(function() {
  var max_fields = 8;
  var wrapper = $(".input_fields_wrap");
  var add_button = $(".add_field_button");

  var x = 1;
  var temp;
  $(add_button).click(function(e) {
    e.preventDefault();
    var i;
    if (x < max_fields) {
      x++;
      i = x - 1;
      temp = i - 1;
      $(wrapper).append('<div class="w3-col m1 w3-margin w3-center prices">Price<input class="w3-input w3-border w3-round" id="price' + i + '" name="price[]" type="text"></div>');
    }

  });


  $("[type='number']").keypress(function(evt) {
    evt.preventDefault();
  });

  $("#price" + 0 + "").on('input', function() {
    alert('price0');
  });
  $("#price" + 1 + "").on('input', function() {
    alert('price1');
  });

});
mplungjan
  • 169,008
  • 28
  • 173
  • 236

0 Answers0