javascript - Automatically show price when we select the ID in PHP -
include "config.php"; $id = $_get['id']; $data = mysql_query("select*from orders orderid=$id"); while ($dat = mysql_fetch_array($data)) { echo "<input type=hidden name=orderid value=$dat[0]>"; } ?> </br> product : <select name="productid"> <option value="0">-product name-</option> <?php $goods = mysql_query("select * products"); while ($data = mysql_fetch_array($goods)) { ?> <option value="<?php echo"$data[productid]"; ?>"><?php echo"$data[productname]"; ?></option> </select> </br> price :<input type="text" name="price" value="<?php echo"$data[unitprice]" ?>" disabled="disabled"></br> <?php } ?> qty : <input type="text" name="quantity"></br> <input type="submit" value="submit">
i dont know how show price automatically when select productid.
can me?
working example on jsfiddle. can via jquery. add id attribute select (id="products"
), data-price attribute options , id attribute input(id="priceinput"
) this:
php , html:
product : <select name="productid" id="products"> <option value="0">-product name-</option> <?php $goods = mysql_query('select * products'); while ($data = mysql_fetch_array($goods)) { ?> <option value="<?php echo $data['productid']; ?>" data-price="<?php echo $data['unitprice']; ?>"><?php echo $data['productname']; ?></option> <?php } ?> </select> </br> price : <input type="text" name="price" id="priceinput" value="" disabled="disabled"></br>
javascript:
$(function () { $('#products').change(function () { $('#priceinput').val($('#products option:selected').attr('data-price')); }); });
i've pulled input
while loop because won't anywhere.
Comments
Post a Comment