Sending Javascript variables.
Posted
by shinjuo
on Stack Overflow
See other posts from Stack Overflow
or by shinjuo
Published on 2010-05-10T17:39:41Z
Indexed on
2010/05/10
17:44 UTC
Read the original article
Hit count: 231
I have a page that allows a user to choose some things in a form and it will calculate the weight using javascript. It breaks it up into 5 variables that I need to send to another page. Originally I was just having it put the variable into a text box and then I was posting that text box. However I dont want to have 5 text boxes. So now I need to somehow send or post the five variables to another page. Here is my javascript function. I need to post weightBoxOne - weightBoxFive
js function
function getWeight(){
var weightBoxOne;
var weightBoxTwo;
var totalWeight;
var box = .5;
var quantity = document.dhform.quantity.value;
var cardSize = document.dhform.cardSize.value;
if(cardSize == 0.0141){
if(quantity <= 1000){
weightBoxOne = (quantity * cardSize) + box;
totalWeight = weightBoxOne;
}else if(quantity > 1000 && quantity <= 2000){
weightBoxOne = (1000 * cardSize) + box;
weightBoxTwo = ((quantity - 1000) * cardSize) + box;
totalWeight = weightBoxOne + weightBoxTwo;
}else if(quantity > 2000 && quantity <= 3000){
weightBoxOne = (1000 * cardSize) + box;
weightBoxTwo = (1000 * cardSize) + box;
weightBoxThree = ((quantity - 2000) * cardSize) + box;
totalWeight = weightBoxOne + weightBoxTwo + weightBoxThree;
}else if(quantity > 3000 && quantity <= 4000){
weightBoxOne = (1000 * cardSize) + box;
weightBoxTwo = (1000 * cardSize) + box;
weightBoxThree = (1000 * cardSize) + box;
weightBoxFour = ((quantity - 3000) * cardSize) + box;
totalWeight = weightBoxOne + weightBoxTwo + weightBoxThree + weightBoxFour;
}else{
weightBoxOne = (1000 * cardSize) + box;
weightBoxTwo = (1000 * cardSize) + box;
weightBoxThree = (1000 * cardSize) + box;
weightBoxFour = (1000 * cardSize) + box;
weightBoxFive = ((quantity - 4000) * cardSize) + box;
totalWeight = weightBoxOne + weightBoxTwo + weightBoxThree + weightBoxFour + weightBoxFive;
}
}else if(cardSize == 0.00949){
if(quantity <= 4000){
weightBoxOne = (quantity * cardSize) + box;
totalWeight = weightBoxOne;
}else{
weightBoxOne = (4000 * cardSize) + box;
weightBoxTwo = ((quantity - 4000) * cardSize) + box;
totalWeight = weightBoxOne + weightBoxTwo;
}
}
document.rates.weight.value = totalWeight;
}
//-->
this is the form that was originally posting
<form action="getRates.php" name="rates" method="post" onSubmit="popupform(this, 'join')">
<table style="width: 216px">
<tr>
<td style="width: 115px; height: 49px;"><span class="style16">Weight</span><br/>
<input type="text" id="weight" name="weight" size="10" maxlength="4"/>
</td>
<td align="right" style="width: 68px; height: 49px;" valign="top"><span class="style16">Zip Code</span><br/>
<input type="text" id="zip" name="zip" size="10" maxlength="5"/>
</td>
</tr>
<tr>
<td style="width: 115px">
<input name="submit" type="submit" value="Get Rate Costs" style="width: 138px" />
© Stack Overflow or respective owner