-1

as the question says, i would like to get the value of the selected value and display the value within a dropdown list if possible. i have attempt but do not seem to get anywhere

<div class="products-prices-calculators-wrap">

            <label for="js-data">Quantity: </label>
            <select id="js-data" <option value="<?php echo $product_min_quantity ?>" </option> </select>



jQuery('#js-data')change(function () {
    var selectedOption = $('js-dataoptions:selected');
user5813072
  • 51
  • 4
  • 15

2 Answers2

1

It is simple

var val = $( "#js-QuantityInputs" ).val();

or you can use this

$("#js-QuantityInputs option:selected").text();

Following lines you have missed '>' at end of the tag

<select id="js-QuantityInputs"
<option value="<?php echo $product_min_quantity ?>" 
Jerald
  • 335
  • 1
  • 10
1

You have some issues in your HTML and jQuery.

  1. <select> box not close properly.
  2. <option> tag not close properly.
  3. syntax error in jQuery near onchange event.

Modified Code:

<select id="js-QuantityInputs">
    <option value="<?php echo $product_min_quantity; ?>">
        <?php echo $product_min_quantity; ?> 
    </option> 
</select>

<script type="text/javascript">
    $( "#js-QuantityInputs" ).change(function() {
      var selectedOption = $('#js-QuantityInputs').val();     
    });
</script>

Side note: make sure you are using jQuery library file in your template.

devpro
  • 16,184
  • 3
  • 27
  • 38