user3805324 user3805324 - 18 days ago 7
HTML Question

How to calculate the price according to the quantity selection in dropdown in HTML

Hi I'm doing a shopping cart like application In my dropdown user should select quantity according to that the price should be changed How to achieve that?
Heard that we can do it using onChange() function in javascript.Help me to achieve this

<p id="price"> <h3> MRP - <?php echo $row['price'] ?> </h3> </p>
<p> Total Price: Total price should load here </p>


<select class="form-control" name='item' id='item' onchange=''>
<option>Select Quantity</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>

</select>

Answer

You can check here the demo Demo Here

function getamount(value)
 {
 var price=$("#price").html().replace ( /[^\d.]/g, '' );
 var amount=parseInt(value)*parseInt(price);
 alert(amount);
 $("#amount").html("Total Price: " +amount);
 }
Comments