In a header file i have which is populated by PHP:
<script type="text/javascript">
var packages = {};
packages[1] = {title:'Pack 1',price:7.50,setup:0.00,template:0};
packages[2] = {title:'Pack 2',price:12.00,setup:0.00,template:0};
packages[3] = {title:'Pack 3',price:25.00,setup:75.00,template:1};
var templates = {};
templates[4] = {title:'Template 1'};
templates[5] = {title:'Template 2'};
templates[6] = {title:'Template 3'};
</script>
<script type="text/javascript" src="/include/jscript/form.inc.js"></script>
Now in the form.inc.js i want the content of the vars packages. So like:
function updatePrices(){
var package_price = 0;
var setup_price = 0;
var package = $_2('#package_select').val();
package_price += packages[package].price;
setup_price += packages[package].setup;
$_2(".package_price").html("£"+package_price);
$_2(".setup_price").html("£"+setup_price);
$_2(".total_price").html("£"+(package_price+setup_price));
}
You see here: packages[package].price that packages[1].price and should show 7.50, but i dont think the var packages is being passed though!
Any help would be awesome thanks
Your script isn’t being run because it has a syntax error in it:
Notice that you’re using single quotes to mark the title strings, but two of the titles have single quotes in them. You need to escape the single quotes with a slash, like so:
Please look at your browser’s JavaScript/Error Console. It’ll do wonders for you =D