javascript - Change the select option value based on input field -


i don't know how it. possible process? want change select option value based on user input on quant field

<input type="number" name="quant" id="quant" /> // example enter 2 <select name="shipment" disable>  <option value="100"> 100 per 1 item </option>  <option value="150"> 150 per 2 item </option> //this must selected </select> 

my actual code in php

    <select name="shipment" id=""> <?php  foreach($shipment $num => $price) {     if($num != null || $price !=null)     { ?>               <option value="<?php echo "{$price}"?>">     <?php echo "{$price}"." "."{$num}"." item";?></option> <?php      } } ?>  </select> <h4 style="padding:0px;margin:0px;float:left;margin-top:10px;"  class="col-md-3" >quantity: </h4> <div class="col-md-9" style="padding-left:0px;"><input  type="number"  name="quant" onblur="multiply.call(this,this.form.elements.price.value,this.form.elements.quant.value)"  min="1" max="10" placeholder="2" style="height:2em;margin:3px;"></div> 

i have make simple calculation price of item:

<h4 style="padding:0px;margin:0px;float:left;"  class="col-md-12" >sale price: ₱<font color='red'><?php $price= number_format(intval($shop_item_orig_price-($shop_item_orig_price*($shop_item_sale/100)))); echo $price;?> </font> </h4> 

i multiply based on quantity

    <input  type="number"  name="quant" onblur="multiply.call(this,this.form.elements.price.value,this.form.elements.quant.value);myfunction(this.value)"  min="1" max="10" placeholder="2" style="height:2em;margin:3px;"> 

and add shipping fee based on selected value.

i showing simple demo question below:

update

function myfunction(quantvalue)  {    var shipmentoption = document.getelementbyid("shipmentselect");    shipmentoption.selectedindex = quantvalue - 1;  }
<input  type="number" name="quant" placeholder="2" onblur="myfunction(this.value)"/>    <select name="shipment" id="shipmentselect">   <option value="100"> 100 per 1 item </option>   <option value="150"> 150 per 2 item </option> //this must selected  </select>

explanation: demo simple logic of selectedindex. assuming entries searialized options. if 1 input select first option, 2 input select second option,.... , on.

second update:

jsfiddle:demo

hope you.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -