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
chchiat
Forum Newbie
Posts: 4 Joined: Tue Mar 22, 2005 4:07 am
Post
by chchiat » Tue Mar 22, 2005 4:16 am
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 = "e;$"e; + 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
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Mar 22, 2005 5:55 am
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
Post
by traherom » Tue Mar 22, 2005 7:02 am
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]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 22, 2005 9:06 am
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
Post
by chchiat » Tue Mar 22, 2005 8:14 pm
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="e;text/javascript"e;>
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 = "e;$"e; + 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="e;init()"e;>
<form method="e;post"e; action="e;http://www.cart.com"e;>
Hard Drive Upgrade<br>
<input type="e;radio"e; name="e;option1|Hard Drive Upgrade"e; value="e;120 GB 7,200 RPM SATA|0.00"e; checked> 120 GB 7,200 RPM SATA - Add $0.00<br>
<input type="e;radio"e; name="e;option1|Hard Drive Upgrade"e; value="e;200 GB 7,200 RPM SATA|39.99"e;> 200 GB 7,200 RPM SATA - Add $39.99<br>
<input type="e;radio"e; name="e;option1|Hard Drive Upgrade"e; value="e;250 GB 7,200 RPM SATA|79.99"e;> 250 GB 7,200 RPM SATA - Add $79.99<br>
<br>Second Hard Drive Options<br>
<input type="e;radio"e; name="e;option2|Second Hard Drive Options"e; value="e;None|0.00"e; checked> None - Add $0.00<br>
<input type="e;radio"e; name="e;option2|Second Hard Drive Options"e; value="e;120 GB 7,200 RPM SATA|108.99"e;> 120 GB 7,200 RPM SATA - Add $108.99<br>
<input type="e;radio"e; name="e;option2|Second Hard Drive Options"e; value="e;200 GB 7,200 RPM SATA|145.99"e;> 200 GB 7,200 RPM SATA - Add $145.99<br>
<input type="e;radio"e; name="e;option2|Second Hard Drive Options"e; value="e;250 GB 7,200 RPM SATA|189.99"e;> 250 GB 7,200 RPM SATA - Add $189.99<br>
<br>Memory Upgrade<br>
<input type="e;radio"e; name="e;option3|Memory Upgrade"e; value="e;512 333 DDR Memory (1 DIMM)|0.00"e; checked> 512 333 DDR Memory (1 DIMM) - Add $0.00<br>
<input type="e;radio"e; name="e;option3|Memory Upgrade"e; value="e;1 GB 333 DDR Memory (2 DIMMs)|79.99"e;> 1 GB 333 DDR Memory (2 DIMMs) - Add $79.99<br>
<br>USB-UIRT IR Blaster Option<br>
<input type="e;radio"e; name="e;option4|USB-UIRT IR Blaster Option"e; value="e;None|0.00"e; checked> None - Add $0.00<br>
<input type="e;radio"e; name="e;option4|USB-UIRT IR Blaster Option"e; value="e;USB-UIRT IR Blaster|49.99"e;> USB-UIRT IR Blaster - Add $49.99<br>
<br>56K Modem Option<br>
<input type="e;radio"e; name="e;option5|56K Modem Option"e; value="e;None|0.00"e; checked> None - Add $0.00<br>
<input type="e;radio"e; name="e;option5|56K Modem Option"e; value="e;56k Modem|20.00"e;> 56k Modem - Add $20.00<br>
<br>Wireless Ethernet Adapter<br>
<input type="e;radio"e; name="e;option6|Wireless Ethernet Adapter"e; value="e;None|0.00"e; checked> None - Add $0.00<br>
<input type="e;radio"e; name="e;option6|Wireless Ethernet Adapter"e; value="e;Linksys WMP5465G|59.99"e;> Linksys WMP5465G - Add $59.99<br>
<input type="e;radio"e; name="e;option6|Wireless Ethernet Adapter"e; value="e;Linksys WMP5465S(Speed Boost)|69.99"e;> Linksys WMP5465S(Speed Boost) - Add $69.99<br>
<br>Wireless Router<br>
<input type="e;radio"e; name="e;option7|Wireless Router"e; value="e;None|0.00"e; checked> None - Add $0.00<br>
<input type="e;radio"e; name="e;option7|Wireless Router"e; value="e;Linksys WRT54G|69.99"e;> Linksys WRT54G - Add $69.99<br>
<input type="e;radio"e; name="e;option7|Wireless Router"e; value="e;Linksys WRT54GS(Speed Boost)|89.99"e;> Linksys WRT54GS(Speed Boost) - Add $89.99<br>
<br>Norton Internet Security<br>
<input type="e;radio"e; name="e;option8|Norton Internet Security"e; value="e;None|0.00"e; checked> None - Add $0.00<br>
<input type="e;radio"e; name="e;option8|Norton Internet Security"e; value="e;12 Month Subscription|39.99"e;> 12 Month Subscription - Add $39.99<br>
<br>
<input type="e;text"e; name="e;totalPrice"e;>
<input type="e;submit"e; name="e;add"e; value="e;Add to Cart"e;></form>
</body>
</html>
feyd | Please review how to post code using Code: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 22, 2005 8:23 pm
What php code have you gotten so far?
..and seriously, post code correctly please.
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Tue Mar 22, 2005 8:46 pm
I don't think he has any PHP code yet... all he has is the JavaScript.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 22, 2005 8:55 pm
yeah.... notice I put his code in
Code: Select all
tags.. they weren't in any tags previously..
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Tue Mar 22, 2005 8:57 pm
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
Post
by chchiat » Tue Mar 22, 2005 10:07 pm
The code i post up is a JAVASCRIPT CODE... i wan to convert it to a PHP code... So... can anyone help me ? tQ ^^
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 22, 2005 10:09 pm
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
Post
by chchiat » Wed Mar 23, 2005 5:14 am
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.. ^^
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed Mar 23, 2005 5:54 am
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....