Passing a textbox dynamically

cs_EPierre Messages postés 1 Date d'inscription dimanche 30 janvier 2005 Statut Membre Dernière intervention 30 janvier 2005 - 30 janv. 2005 à 07:11
the_smurf Messages postés 283 Date d'inscription vendredi 6 août 2004 Statut Membre Dernière intervention 22 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;

//if(tpscan == true)
{(tpscan.value=Number(total.value)*Number(0.07));}
//else
//{("");}
canexpd.value=0;
{canexpd.value=Number(6.50)+(Number(2.50)*(Number(qte[ind].value)-Number(1)));}

usexpd.value=0;
{usexpd.value=Number(8.50)+(Number(3.50)*(Number(qte[ind].value)-Number(1)));}

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 |

<!-- ITEMS -->
----

Le Roi de la Havane,
,
,
,

<!-- Livre # 2 -->
----

A la recherche de Jean-Rabel,
,
,
,

<!-- Livre # 3 -->
----

Si Port-au-Prince m'était conté,
,
,
,

<!-- Livre # 4 -->
----

Haïti, de l'indépendance à la dépendance,
,

<center>

Montant brut de la commande:,
,

<!-- TPS -->
----

Expédition:,

<!-- TPS CANADA -->
----

Canada:,
TPS: 7.00% (Rxxx.xxxx), </td></td>

<!-- TPS non applicables à -->
----

Hors Canada:,
Taxes non applicables,

----

Les Frais d'expédition,

----

Canada:,
, </TD>

----

USA:,
, </TD>

----

Tous autres pays:,
, </TD>

</HTML>
[QUOTE]

1 réponse

the_smurf Messages postés 283 Date d'inscription vendredi 6 août 2004 Statut Membre Dernière intervention 22 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
0
Rejoignez-nous