0

on dropdown change i would like to put the price on the textbox "price" base on the selected value in dropdown

        function Price(data) {

        document.getElementById ("productprice").value = data.value;

        }


        <select name="product" onchange="Price(this)">
    <option value="" disabled="disabled" selected="selected">Please select a product</option>
    <?php
    foreach ($product as $product) {
    ?>
    <option value="<?php echo $product['Product']?>" id="<?php echo $product['Price']?>"><?php echo $product['Product'] . " Qty: " . $product['Quantity']?></option>
    <?php
    }
    ?>
    </select>


    <input id="productprice" type="text" name="price" />

i did get try to multi value but how do i only get the 2nd value to appear in textbox

<select name="product" onchange="Price(this)">
    <option value="" disabled="disabled" selected="selected">Please select a product</option>
    <?php
    foreach ($product as $product) {
    ?>
    <option value="<?php echo $product['Product']?>,<?php echo $product['Price']?>"><?php echo $product['Product'] . " Qty: " . $product['Quantity']?></option>
    <?php
    }
    ?>
    </select>

Edited by Shodow

2
Contributors
4
Replies
12
Views
4 Years
Discussion Span
Last Post by Echo89
0

OK, This should work:

document.getElementById("productprice").value = data.options[data.selectedIndex].id;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.