Function script help needed…

Hello,

Scripting isn’t my thing, but I’m trying by using and combining scripts.
[b] :-\ Can somebody help me, I’ve tried to work around this problem for days. :-[/b]

I need to calculate a total out of a session with the total shipping costs.
This are “ totaal” and “products” . and need 2 decimals (money).

The first part works:
[php]function selectedValue(v) { return (v.selectedIndex < 0) ? 0 : parseFloat(v[v.selectedIndex].value);}

function BerekenTotaal() {
var f = document.VerzendKosten;
var totaal = (selectedValue(f.landverz) + selectedValue(f.trackentrace)).toFixed(2);
f.totaaltext.value = totaal [/php]

When I use the second part it will put the two values behind each other
(Value 1 = 19.30) + (Value 2 = 425) = (Total = 19.30425) ???
[php]products = document.getElementById(‘subtotaal’).value;
uitkomst = totaal + products;
document.getElementById(‘ordertotal’).value = uitkomst;[/php]

The partial working code of the form:
[php]<?php
// Session
include("./inc/session.php");
?>

<?php // URL include("./weergeven/url.php"); ?> Bestel formulier <!-- .style1 { font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; } .style2 { font-family: Arial, Helvetica, sans-serif; font-size: 12px; }

–>

Bestelformulier

  <tr><td  colspan=2 width="100%"><hr><span class="style1">Verzendkosten:</span>
Uw land:
-----------------------Kies ------------------------------------------ Albanië Andora Azoren België Bosnië-Herzegovina Bulgarije Canarische Eilanden Corsica Cyprus Denemarken (Excl. Faeröer Eilanden en Groenland) Duitsland Engeland Estland Faeröer Eilanden Finland Frankrijk (Incl. Carsica en Monaco)) Gibraltar Griekenland Guernsey Hongarije Ierland IJsland Italië (Excl. San Marino en Vaticaanstad) Jersey Kroatië Letland Luxemburg Madeira Malta Moldavië Monaco Montenegro Nederland Noorwegen Oekraïne Oostenrijk Polen Portugal (Incl. Azoren en Madeira) Roemenie San Marino Servië Slovenië Slowakije Spanje (Incl. Balearen, exclusief Canarische eilanden) Tsjechië Turkije Vaticaanstad Verenigd Koninkrijk (Excl. Gibraltar en Kanaaleilanden) Wit-Rusland Zweden Zwitserland
Verzend opties:
-----------------------Kies ------------------------------------------ Track & Trace Verzekerd (500,- Euro) Verzekerd (5.500,- Euro)
Verzendkosten : €
<tr>
  <td colspan=2 valign="bottom"><hr></td>
</tr>	


<tr>
  <td bgcolor=green valign="bottom"><span class="style1">
	Totaal
  </span></td>
        <td bgcolor=yellow align="right"><span class="style1">

<input id="ordertotal" type="text" readonly="readonly" maxlength="8" size="4" tabindex="1" name="1" value="0"  align="right">

  </span></td>
</tr>	

<input type=“hidden” name=“ip” id=“ip” value="<?php $ip=@$REMOTE_ADDR; echo "$ip"; ?>" />


[/php]

Thanks,

Rob

how about…

f.totaaltext.value = “$”.number_format($totaal, 2, ‘,’, ’ ');

Thanks for the replay,

But up to there it is working, and it even calculate correctly with 2 decimals.
So the first part with the two dropdownboxes is correct.

But after that I added a new value “products”

[php]

[/php]

So the part :
[sub]products = document.getElementById(‘subtotaal’).value;
uitkomst = totaal + products;
document.getElementById(‘ordertotal’).value = uitkomst;
[/sub]is not correct…

? hints ?

Oay,
I’ve uploaded the page to : <copy/past> http://0042.nl/phphelp/orderForumvraag.php </copy/past> .
Where you can see what is happening.

Gray part works fine, that is the first part of the function.
Now I need to add the (green) value and get a new total in the yellow field.
This is the next part, am I mising something?
[sub]products = document.getElementById(‘subtotaal’).value;
uitkomst = totaal + products;
document.getElementById(‘ordertotal’).value = uitkomst;[/sub]

So the html code is a little changed.
[php]

Bestel formulier <!-- .style1 { font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; } .style2 { font-family: Arial, Helvetica, sans-serif; font-size: 12px; }

–>

Bestelformulier

  <tr><td  colspan=2 width="100%"><hr><span class="style1">Verzendkosten:</span>
Uw land:
-----------------------Kies ------------------------------------------ Albanië Andora Azoren België Bosnië-Herzegovina Bulgarije Canarische Eilanden Corsica Cyprus Denemarken (Excl. Faeröer Eilanden en Groenland) Duitsland Engeland Estland Faeröer Eilanden Finland Frankrijk (Incl. Carsica en Monaco)) Gibraltar Griekenland Guernsey Hongarije Ierland IJsland Italië (Excl. San Marino en Vaticaanstad) Jersey Kroatië Letland Luxemburg Madeira Malta Moldavië Monaco Montenegro Nederland Noorwegen Oekraïne Oostenrijk Polen Portugal (Incl. Azoren en Madeira) Roemenie San Marino Servië Slovenië Slowakije Spanje (Incl. Balearen, exclusief Canarische eilanden) Tsjechië Turkije Vaticaanstad Verenigd Koninkrijk (Excl. Gibraltar en Kanaaleilanden) Wit-Rusland Zweden Zwitserland
Verzend opties:
-----------------------Kies ------------------------------------------ Track & Trace Verzekerd (500,- Euro) Verzekerd (5.500,- Euro)
Verzendkosten : €
<tr>
  <td colspan=2 valign="bottom"><hr></td>
</tr>	


<tr>
  <td bgcolor=green valign="bottom"><span class="style1">
	<input type="text" name="subtotaal" id="subtotaal" value="425"	>
  </span></td>
        <td bgcolor=yellow align="right"><span class="style1">

<input id="ordertotal" type="text" readonly="readonly" maxlength="8" size="4" tabindex="1" name="1" value="0"  align="right">

  </span></td>
</tr>	

<input type=“hidden” name=“ip” id=“ip” value="<?php $ip=@$REMOTE_ADDR; echo "$ip"; ?>" />


[/php] Thanks,

Rob

forgive me if I’m misunderstanding, but…

I gave you the answer!

Put 'number_format($somefloat, 2, ‘,’, ’ ‘);’ everywhere you want formatted output. Replace $somefloat with your number.

Thanks aztech4mac for your patience :wink:
Yes you did answer (sorry).

If I start to replace that line the script doesn’t work anymore.
I googled and played around with it but I keep on doing it wrong.
I’m a total nope (and probably stay) in scripting ;D, I hoped to get this solved to get on with the parts I do understand. It is the last step in the ***** form I need to solve… :’(

Can anybody finish this script or give me a boost to the right way ?
(aztech4mac already started but it’s probably me…)

‘+’ acts as a string concatenation operator in javascript. :slight_smile: :stuck_out_tongue:
[php]
use:
uitkomst =parseFloat(totaal) + parseFloat(products) instead of uitkomst = totaal + products

[/php]

Thanks,

That was all…
If you know… it is easy…

Sponsor our Newsletter | Privacy Policy | Terms of Service