Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change Script to work with Radio Buttons

    hey guys, is there any way I can get this script to work with radio buttons? Ty


    Code:
    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!

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no idea if it works in IE (specifically the line red...)
    Code:
    <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.
    Last edited by fci; 11-13-2004 at 09:10 AM.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    kk thanks

  • #4
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I edited my post at the exact same time you replied !

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol thanks will try

    beautiful thanks!
    Last edited by MitaDC; 11-13-2004 at 04:03 PM.

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by MitaDC; 11-13-2004 at 05:20 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •