开发者

Javascript - How to change a new value on drop down

When we change the name="quantity" and the $product['price'] value will changing too. Here will have dynamic quantity and price. How to do that using jquery/javascript.

<?php
$select  = "SELECT * FROM `products` ORDER BY `id` DESC LIMIT 10"; 
$query  = mysql_query($select) or die(mysql_error());
?>

<ul>
  <?php while($product = mysql_fetch_array($query)) { ?>
  <li>
    <p><?php echo $product['name'];?></p>
    <p> Quantity
      <select name="quantity">
        <?php  for($i=1;$i<=$product['quantity'];$i++) { ?>
        <option value="<?php echo $i; ?>"><?php开发者_如何学Python echo $i; ?></option>
        <?php } ?>
      </select>
   </p>
   <p><?php echo $product['price'];?></p>
 </li>
<?php } ?>
</ul>

Let me know :)


Using jQuery:

$(document).ready(function() {
    $("#quantity_select").bind("change", function() {
        selected_option = $("option:selected").val();
        $("#counter").html(selected_option);
    });
});

...

<select id="quantity_select">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>

<div id="counter"></div>

You can use text() instead of val() if you want to see actual text instead of value attribute .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜