troubleshooting Question

html form calculate price with input

Avatar of webdott
webdottFlag for United States of America asked on
Web Languages and StandardsJavaScriptHTML
15 Comments1 Solution770 ViewsLast Modified:
i have the attached code, how can i add to it, like:

how many do you want?
input box -- I can enter in number 10 for example

price is $1 each

in the total box, it will take 10 x $1 = $10
and add that to any of the radio boxes total.

i hope that explains it.

thanks

<html>
    <head>
    <script type="text/javascript">
    
    function calculate(){
        var radioArray = new Array();
        var formObj = document.forms[0];
        var totalPrice = 0;
        for(var no=0;no<formObj.elements.length;no++){        
            if(formObj.elements[no].type=='radio' && !radioArray[formObj.elements[no].name]){
                
                var obj = formObj.elements[formObj.elements[no].name];
                for(var no2=0;no2<obj.length;no2++){
                    if(obj[no2].checked){
                        radioArray[formObj.elements[no].name] = true;
                        var stringArray = obj[no2].value.split('|');
                        var price = stringArray[1];
                        totalPrice = totalPrice/1 + price /1;
                    }                
                }
            }        
        }
        totalPrice = Math.round(totalPrice*100);
        totalPrice = totalPrice/100;
        document.forms[0].totalPrice.value = "$" + totalPrice;
    }
    
    
    function init(){
        for(var no=0;no<document.forms[0].elements.length;no++){
            if(document.forms[0].elements[no].type=='radio'){
                document.forms[0].elements[no].onclick=calculate;
            }
        }
    }
    </script>
<script language="javascript" type="text/javascript">

function PrintMeSubmitMe()
{
window.print();
}

function SubmitMe()
{
document.MyForm.submit();
}
</script>
    </head>
<body onload="init()">

<form  name="MyForm" action="somepage.asp" method="post">
Hard Drive Upgrade<br>
<input type="radio" name="option1|Hard Drive Upgrade" value="120 GB 7,200 RPM SATA|0.00" checked> 120 GB 7,200 RPM SATA - Add $0.00<br>
<input type="radio" name="option1|Hard Drive Upgrade" value="200 GB 7,200 RPM SATA|39.99"> 200 GB 7,200 RPM SATA - Add $39.99<br>
<input type="radio" name="option1|Hard Drive Upgrade" value="250 GB 7,200 RPM SATA|79.99"> 250 GB 7,200 RPM SATA - Add $79.99<br>
<br>Second Hard Drive Options<br>
<input type="radio" name="option2|Second Hard Drive Options" value="None|0.00" checked> None - Add $0.00<br>
<input type="radio" name="option2|Second Hard Drive Options" value="120 GB 7,200 RPM SATA|108.99"> 120 GB 7,200 RPM SATA - Add $108.99<br>
<input type="radio" name="option2|Second Hard Drive Options" value="200 GB 7,200 RPM SATA|145.99"> 200 GB 7,200 RPM SATA - Add $145.99<br>
<input type="radio" name="option2|Second Hard Drive Options" value="250 GB 7,200 RPM SATA|189.99"> 250 GB 7,200 RPM SATA - Add $189.99<br>
<br>Memory Upgrade<br>
<input type="radio" name="option3|Memory Upgrade" value="512 333 DDR Memory (1 DIMM)|0.00" checked> 512 333 DDR Memory (1 DIMM) - Add $0.00<br>
<input type="radio" name="option3|Memory Upgrade" value="1 GB 333 DDR Memory (2 DIMMs)|79.99"> 1 GB 333 DDR Memory (2 DIMMs) - Add $79.99<br>
<br>USB-UIRT IR Blaster Option<br>
<input type="radio" name="option4|USB-UIRT IR Blaster Option" value="None|0.00" checked> None - Add $0.00<br>
<input type="radio" name="option4|USB-UIRT IR Blaster Option" value="USB-UIRT IR Blaster|49.99"> USB-UIRT IR Blaster - Add $49.99<br>
<br>56K Modem Option<br>
<input type="radio" name="option5|56K Modem Option" value="None|0.00" checked> None - Add $0.00<br>
<input type="radio" name="option5|56K Modem Option" value="56k Modem|20.00"> 56k Modem - Add $20.00<br>
<br>Wireless Ethernet Adapter<br>
<input type="radio" name="option6|Wireless Ethernet Adapter" value="None|0.00" checked> None - Add $0.00<br>
<input type="radio" name="option6|Wireless Ethernet Adapter" value="Linksys WMP5465G|59.99"> Linksys WMP5465G - Add $59.99<br>
<input type="radio" name="option6|Wireless Ethernet Adapter" value="Linksys WMP5465S(Speed Boost)|69.99"> Linksys WMP5465S(Speed Boost) - Add $69.99<br>
<br>Wireless Router<br>
<input type="radio" name="option7|Wireless Router" value="None|0.00" checked> None - Add $0.00<br>
<input type="radio" name="option7|Wireless Router" value="Linksys WRT54G|69.99"> Linksys WRT54G - Add $69.99<br>
<input type="radio" name="option7|Wireless Router" value="Linksys WRT54GS(Speed Boost)|89.99"> Linksys WRT54GS(Speed Boost) - Add $89.99<br>
<br>Norton Internet Security<br>
<input type="radio" name="option8|Norton Internet Security" value="None|0.00" checked> None - Add $0.00<br>
<input type="radio" name="option8|Norton Internet Security" value="12 Month Subscription|39.99"> 12 Month Subscription - Add $39.99<br>
<br>
<input type="text" name="totalPrice">
<input type="button" value="Print Quote" onclick="PrintMeSubmitMe(this)"></form>

</body>
</html>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros