javascript - Change the value of a variable on the fly depending on the selection of a Select -


i have following php code print html , have variable $price , $numofguests

<?php echo '$' . $price ;  $i = 1; //this print values of number of guest example: 1,2,3,4 echo 'select number of guests'; echo '<select name="numberofguests">'; while ($i <= $numofguests):         echo $i;     echo '<option value="' .$i. '">' .$i. '</option>';          $i++; endwhile; echo '</select>';  ?> 

how print out on fly total price depending on user selection?

example: let's $price = $5 , number of guest options are: 1,2,3

so default num of guest going 1 , total price = $5

but if user select num of guest = 2 total price change $10 , if num of guest = 3 total price change $15

thank much

try one.

 <div id="pricediv"></div>     <?php     $numofguests = 5;     $i = 1;     echo 'select number of guests'."</br>";     echo '<select name="numberofguests" onchange="total(this.value)">';     while ($i <= $numofguests):             echo $i;         echo '<option value="' .$i. '">' .$i. '</option>';              $i++;     endwhile;     echo '</select>';      ?>      <script>     function total(guest){     var price = guest*5;     document.getelementbyid("pricediv").innerhtml="price "+guest+" guests $"+price;      }      </script> 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -