Help ! Please help me to convert it to PHP script !

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chchiat
Forum Newbie
Posts: 4
Joined: Tue Mar 22, 2005 4:07 am

Help ! Please help me to convert it to PHP script !

Post by chchiat »

Hello,
This function below is calculating several price using radio select button... but it written using javascript, can any one help me to convert to a PHP format ? so that i can include it into my php page... TQ !

Code: Select all

<!--
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;no2obj.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 = &quote;$&quote; + 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;
            }
        }
    }
--!>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

If its already in javascript why not just include the javascript in your php page?

You're gonna need to modify the form for this to work.... the JS is using object indexes etc rather than names like PHP would use.
traherom
Forum Newbie
Posts: 13
Joined: Tue Mar 15, 2005 6:43 am

Form names

Post by traherom »

It would be helpful (to me at least) to see the code of the entire page. That way we can know exactly what you are doing and give you html with the form names in a way which is easiest to process.

And, as a side note... feyd isn't going to like the lack of [syntax=php]tags.[/syntax]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: Form names

Post by feyd »

traherom wrote:And, as a side note... feyd isn't going to like the lack of

Code: Select all

tags. [/quote]darn straight I don't.. 


converting to php shouldn't be hard.. just need more code to see what things will be submitted as and such... but basiclly, just do like the Javascript works.. find the radio button fields, explode() the value, sum with total price, and so on...
chchiat
Forum Newbie
Posts: 4
Joined: Tue Mar 22, 2005 4:07 am

Please help again ! =) convert to php

Post by chchiat »

Basically the form work as below... I give u the full page of code... I need to convert it to php script. Please help me ! Thanks...

Code: Select all

<html>
    <head>
    <script type=&quote;text/javascript&quote;>
    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;no2obj.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 = &quote;$&quote; + 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>
    </head>
<body onload=&quote;init()&quote;>

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

</body>
</html>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What php code have you gotten so far?

..and seriously, post code correctly please.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I don't think he has any PHP code yet... all he has is the JavaScript.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yeah.... notice I put his code in

Code: Select all

tags.. they weren't in any tags previously..
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

What php code have you gotten so far?
Oh. I must have misinterpreted your question.
chchiat
Forum Newbie
Posts: 4
Joined: Tue Mar 22, 2005 4:07 am

Code

Post by chchiat »

The code i post up is a JAVASCRIPT CODE... i wan to convert it to a PHP code... So... can anyone help me ? tQ ^^
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what..have..you..done..so..far..to..convert?

We're not here to do everything for you.
chchiat
Forum Newbie
Posts: 4
Joined: Tue Mar 22, 2005 4:07 am

Reply

Post by chchiat »

Sofar... 0 php have been converted ! actually i only need this page to right out in php code , then i can continue other pages... i just need this page to be converted then others i will done it my own.. ^^
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Do you understand the javascript version? Do you have access to http://www.php.net/ ?

That should get you started. I don't think anybody is going to sit down and do it for you when you could have a go yourself.... :roll:
Post Reply