...

View Full Version : Change Script to work with Radio Buttons



MitaDC
11-13-2004, 07:36 AM
hey guys, is there any way I can get this script to work with radio buttons? Ty




function init() {
//change curr_sel to new price
curr_sel = { start_price:399 };
var sels = document.getElementsByTagName('select');
for(var i = 0; i < sels.length; i++) {
curr_sel[sels[i].name] = 0;

}
price_update();
}
function change_rel_price(list) {
var text, base;
list.options[list.selectedIndex].text.search(/\[\$(.*?)\]$/);
base = Number(RegExp.$1);
for(var i = 0; i < list.options.length; i++) {
text = list.options[i].text;
text = text.replace(/\[\$(.*?)\]$/, function(str, cost) { return '[$' + (Number(cost) - base) + ']' });
list.options[i].text = text;
}
curr_sel[list.name] += base;
price_update();
}
function price_update() {
var total = 0;
for(price in curr_sel) {
total += curr_sel[price];
}
document.getElementById('total').firstChild.nodeValue = 'Price: $' + total;
}
window.onload = init;


Page that it will be on: www.a-lantech.com/systems/budget/ALT-700.html


Thanks Guys!

fci
11-13-2004, 08:43 AM
no idea if it works in IE (specifically the line red...)

<script>
function product(baseprice)
{
this.form = 0;
this.price = baseprice;
this.id = "prod_price";
this.collector = {};
this.adjust = function(obj, price)
{
switch (obj.type) {
case 'checkbox' :
if (this.collector[obj.name] && !obj.checked) {
this.price -= this.collector[obj.name];
} else {
this.collector[obj.name] = price;
this.price += +(price);
}
break;
case 'radio' :
if (this.collector[obj.name]) {
this.price -= this.collector[obj.name];
}
this.collector[obj.name] = price;
this.price += +(price);
break;
}
this.update();
};
this.update = function() { document.getElementById(this.id).innerHTML = this.price; }
/*
this.cycle = function()
{
var form = document.forms[this.form]
var len = form.elements.length;
while (len-->0) {
form.elements[len].checked && form.elements[len].click();
}
return true;
};
*/
this.add = function(name, price)
{
this.adjust(document.forms[this.form].elements[name][0], price);
};

}
var comp = new product(300); // baseprice
//window.onload = function() { comp.cycle() };
</script>
Price: $<span id="prod_price"></span><script>comp.update();</script><br>
<form>
<input type="radio" name="radio_1" value="id_asdfasdf" onClick="comp.adjust(this, 30)" checked>Coding Forums [$30]<br>
<input type="radio" name="radio_1" value="id_asdfasdf" onClick="comp.adjust(this, 10)">Mid-Tower - White [$10]<br>
<input type="radio" name="radio_1" value="id_asdfasdf" onClick="comp.adjust(this, 50)">Mid-Tower - White [$50]<br>
<br>
<input type="radio" name="radio_2" value="id_asdfasdf" onClick="comp.adjust(this, 90)" checked>Mid-Tower - White [$90]<br>
<input type="radio" name="radio_2" value="id_asdfasdf" onClick="comp.adjust(this, 13)">Mid-Tower - White [$13]<br>
<input type="radio" name="radio_2" value="id_asdfasdf" onClick="comp.adjust(this, 53)">Mid-Tower - White [$53]<br>
<input type="checkbox" name="check_me" value="id_asdfasdf" onClick="comp.adjust(this, 100)">WWWWhite [$53]<br>
</form>
<script>
comp.add('radio_1',30);
comp.add('radio_2',90);
</script>

the stuff in blue is what you want to pay attention to.

MitaDC
11-13-2004, 09:10 AM
kk thanks :)

fci
11-13-2004, 09:11 AM
I edited my post at the exact same time you replied !

MitaDC
11-13-2004, 04:01 PM
lol thanks will try :)

beautiful :) thanks!

MitaDC
11-13-2004, 04:42 PM
one q, how do I make sure the radio buttons reset after a refresh? The price changes but the radio buttons stay where they were before the refresh... ty
nvm got it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum