Hello. I am using a lightbox form with a drop-down list. When I choose a value from the dropdown list, I want it to be assigned to a php variable which I will then use to update the total price of the form (the total price is already defined in the form). Here is the link to the relevant page: https://mobilitypro.eu/course/e-learning-blended-learning-and-introduction-to-web-designing/ . When the user clicks Book Now, the lightbox form appears. The problem is with the dropdown list "Select package": when an option is selected, I cannot pass its numerical value to a php variable (before submitting the form). I tried with Ajax to send the value to another php file, but it did not work. Here below is my code, as well as some related pre-existing code of the lightbox-form. I look forward to your help, as I have been trying to find a solution for a long time.
<script>
function getval(sel)
{
var singleValues = sel.value;
var price = <?php echo $price ?> * singleValues;
alert(price); //this is working
}
</script>
<p class="gdlr-lms-half-right">
<span><?php _e('Select package*', 'gdlr-lms'); ?></span>
<select id="package" onchange="getval(this);">
<option value="1">Package 1</option>
<option value="1.5">Package 2</option>
<option value="2.55">Package 3</option>
</select>
</p> <?php $price=$price ?> //this is not working
Pre-existing code preceding my code:
<?php
$price = empty($course_option['discount-price'])? $course_option['price']: $course_option['discount-price'];
$price = floatval($price);
?>
Pre-existing code following my code:
<p class="gdlr-lms-half-right"> <?php _e('Total Price', 'gdlr-lms'); ?>
<input type="text" class="price-display" value="<?php echo gdlr_lms_money_format(($price * $fix_val['amount']) - $fix_val['coupon-discount']); ?>" disabled />
<input type="hidden" class="price" name="price" value="<?php echo (($price * $fix_val['amount']) - $fix_val['coupon-discount']); ?>" />
<input type="hidden" class="price-one" name="amount" value="<?php echo $price; ?>" />
<input type="hidden" class="format" value="<?php echo $lms_money_format; ?>" /> </p>