cs_EPierre
Messages postés1Date d'inscriptiondimanche 30 janvier 2005StatutMembreDernière intervention30 janvier 2005
-
30 janv. 2005 à 07:11
the_smurf
Messages postés283Date d'inscriptionvendredi 6 août 2004StatutMembreDernière intervention22 juin 2006
-
31 janv. 2005 à 15:05
Hello All,
I have a problem. May be someone can help me.
When a user fill a text box (3 possible countries for ex) in a phpmail, I want to get the shipping price dynamically inserted.
As I'm not proficient in JS, the best I can do follows:
quote:
<HR>
<HR>
JS Script
[QUOTE]
<HTML>
<HEAD>
<TITLE>Bon de commande</TITLE>
<script type="text/javascript">
function calcul(ind)
{
res[ind].value=Number(pri[ind].value)*Number(qte[ind].value);
total.value=0;
for (var n=0;n<res.length;n++)
{total.value=Number(total.value)+Number(res[n].value); }
// TPS Canada seulement
tpscan.value=0;
//tpsautre.value=0;
autrexpd.value=0;
{autrexpd.value=Number(9.75)+(Number(4.75)*(Number(qte[ind].value)-Number(1)));}
}
// decimal
function roundNumber(number) {
var rlength = 2; // The number of decimal places to round to
var newnumber = Math.round(number*Math.pow(10,rlength))/Math.pow(10,rlength);
return pad_with_zeros(newnumber, 2)
}
function pad_with_zeros(rounded_value, decimal_places) {
// Convert the number to a string
var value_string = rounded_value.toString()
// Locate the decimal point
var decimal_location = value_string.indexOf(".")
// Is there a decimal point?
if (decimal_location == -1) {
// If no, then all decimal places will be padded with 0s
decimal_part_length = 0
// If decimal_places is greater than zero, tack on a decimal point
value_string += decimal_places > 0 ? "." : ""
}
else {
// If yes, then only the extra decimal places will be padded with 0s
decimal_part_length = value_string.length - decimal_location - 1
}
// Calculate the number of decimal places that need to be padded with 0s
var pad_total = decimal_places - decimal_part_length
if (pad_total > 0) {
// Pad the string with 0s
for (var counter = 1; counter <= pad_total; counter++)
value_string += "0"
}
return value_string
}
</script>
</HEAD>
<!-- En-tête -->
<center>
Items |
Prix unitaire ($can) |
Quantité |
Total |
the_smurf
Messages postés283Date d'inscriptionvendredi 6 août 2004StatutMembreDernière intervention22 juin 2006 31 janv. 2005 à 15:05
To access the value of those following fields:
You can use in JS:
document.getElementsByName("canexpd")[0].value
document.getElementsByName("usexpd")[0].value
document.getElementsByName("autrexpd")[0].value
If you give the same name to your fields, 3 times something like this:
You can get the values using
document.getElementsByName("country")[numberOfYourField].value
with numberOfYourField = 0 for the first, 1 for the 2 an so on.
The SMURF
[mailto:the_little_smurf@yahoo.fr the_little_smurf@yahoo.fr]
Enjoy the life, don't waste your time in front of your computer