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>

EDIT, I had it wrong. Give me a sec!

OK, This should work:

document.getElementById("productprice").value = data.options[data.selectedIndex].id;

tnx man

No problem!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.