I can not get prices to auto update.
To make unique id’s; for the price I use:
id="target_1_<?php echo $product['product_id']; ?>"
and for the select menu I use:
id="select_<?php echo $product['product_id']; ?>"
Here is the html/php
<?php foreach ($products as $product) { ?>
<span id="target_1_<?php echo $product['product_id']; ?>"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['options']) { ?>
<?php foreach ($product['options'] as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<select name="option[<?php echo $option['product_option_id']; ?>]" class="select_options" id="select_<?php echo $product['product_id']; ?>" onchange="getIt(this);">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><span id="newPrice"><?php echo $option_value['price']; ?></span>)
<?php } ?>
</option>
<?php } ?>
</select>
<?php } ?>
........
<?php } ?>
Then for the onchange function I use this:
function getIt(el) {
var a = el.options[el.selectedIndex].text;
var position1 = a.indexOf("(");
var position2 = a.indexOf(")");
var position1 = position1+2
var finalA = a.substring(position1, position2);
document.getElementById("target_1_<?php echo $product['product_id']; ?>").innerHTML = "$"+finalA;
}
alert(finalA) gives the value I need, I just can’t seem to get it back into the DOM
change these two :
pass product_id in getIt function
use id with productid argument concanate instead of using php