开发者

Help with javascript to display cost in label

开发者 https://www.devze.com 2023-01-18 00:28 出处:网络
I\'m completely new to javascript and I was wondernig if someone could help me with probably a simple query!

I'm completely new to javascript and I was wondernig if someone could help me with probably a simple query!

I have the following code: http://jsfiddle.net/J47E6/

I've managed to get the hide/show functions to work, but what I'm struggling 开发者_如何学Gowith is getting the price to display in the label.

Can someone point me in the right direction?


New version of your script is now corrected. I noticed you missed an id selector in your jQuery (#) for discountSelection.

The method now works, but problem is, I'm unsure of how to caculate your math therefor I cannot complete it.

$('#discountselection').hide();
$('#costlabel').hide();

$('#No').click(function() {
    $('#discountselection').hide();
    $('#costlabel').hide();
});

$('#Yes').click(function() {
    $('#discountselection').show();
    $('#costlabel').show();
});


$("#discountselection").change(function()  { 

var selected_value = $("#discountselection option:selected").val();

alert("Selected Value = " + selected_value);
var discount = {1: 12, 2: 24, 3: 36};

var package_prices = {'standard': 45, 'premium': 85, 'platinum': 134 };

var cost = 2; //package_prices[package] * discount[discountselection];
alert("Cost " + cost);
$("#costlabel").val(cost);

}); ​

Where does 'package' and 'discountSelection' come from. answer those and this'll be done for you.

package_prices[package] * discount[discountselection];


Have a look at: revised code

There were a number of errors in JS and inconsistencies in the markup.

0

精彩评论

暂无评论...
验证码 换一张
取 消