gwmbox
01-07-2011, 01:17 AM
Hi guys, I am using a script that was provided to me for changing an image based on the selection of several selects (http://www.dynamicdrive.com/forums/showthread.php?t=59873)
However now what I am trying to do is set a value for quantity and have that change the result if the quantity changes. My modified code looks like;
function mpdprice(){
var mpprice = '1';
var string = document.getElementById('quantity-input').value;
if (string == '1'){
mpprice='22.80';
}
else if (string >= '2' && string <= '24' ){
mpprice='22.08';
}
else if (string >= '25' && string <= '49' ){
mpprice='21.36';
}
else if (string >= '50' && string <= '99' ){
mpprice='19.93';
}
else if (string >= '100' && string <= '249' ){
mpprice='18.49';
}
else if (string >= '250'){
mpprice='17.06';
}
document.getElementById('matprice').innerHTML='$'+mpprice+' each';
}
and the HTML for the price value and that field is
<span id="matprice">$22.80 each</span>
<input type="text" maxlength="5" value="1" id="quantity-input" onchange="mpdprice();">
While it appears to work some values are not correct, if you test it you will see for example setting a quantity to 10 gives $1.00????
Please help me fix the code.
Thanks
GW
However now what I am trying to do is set a value for quantity and have that change the result if the quantity changes. My modified code looks like;
function mpdprice(){
var mpprice = '1';
var string = document.getElementById('quantity-input').value;
if (string == '1'){
mpprice='22.80';
}
else if (string >= '2' && string <= '24' ){
mpprice='22.08';
}
else if (string >= '25' && string <= '49' ){
mpprice='21.36';
}
else if (string >= '50' && string <= '99' ){
mpprice='19.93';
}
else if (string >= '100' && string <= '249' ){
mpprice='18.49';
}
else if (string >= '250'){
mpprice='17.06';
}
document.getElementById('matprice').innerHTML='$'+mpprice+' each';
}
and the HTML for the price value and that field is
<span id="matprice">$22.80 each</span>
<input type="text" maxlength="5" value="1" id="quantity-input" onchange="mpdprice();">
While it appears to work some values are not correct, if you test it you will see for example setting a quantity to 10 gives $1.00????
Please help me fix the code.
Thanks
GW