select option pass two values code example

Example: on select pass 2 values

<select>
	<option data-mrp="1" data-price="2" value="x" >x</option>
</select>

<script type="text/javascript" src="assets/assets/jquery-1.11.0.js"></script>
<script type="text/javascript">
   var basePrice = 0;
   var mrpPrice = 0;
      $(".calculate<?= $p_id; ?>").change(function () {
             newPrice = basePrice;
             newmrpPrice = mrpPrice;
             $(".calculate<?= $p_id; ?> option:selected").each(function () {
                      newPrice += parseFloat($(this).data('price'));
                      newmrpPrice += parseFloat($(this).data('mrp'));
                      console.log(typeof newPrice);
                      console.log(typeof newmrpPrice);
             });
             newPrice = newPrice.toFixed(0);
             newmrpPrice = newmrpPrice.toFixed(0);
             $("#item-price<?= $p_id; ?>").html(newPrice);
             $("#mrp<?= $p_id; ?>").html(newmrpPrice);
       });
</script>

Tags:

Html Example