【发布时间】:2010-05-10 17:39:41
【问题描述】:
我有一个页面,允许用户在表单中选择一些东西,它会使用 javascript 计算权重。它将它分成 5 个变量,我需要将它们发送到另一个页面。最初我只是让它把变量放到一个文本框中,然后我发布了那个文本框。但是我不想有 5 个文本框。所以现在我需要以某种方式将这五个变量发送或发布到另一个页面。这是我的javascript函数。我需要发布 weightBoxOne - weightBoxFive
js函数
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;
}
//-->
这是最初发布的表格
<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" />
【问题讨论】:
-
只需设置一个快速的 json web 服务并使用 jquery 的 post 功能,或其他一些流行的 ajax 框架(虽然 jquery 是最好的)
-
...你不能用数组代替
weightBoxNineThousand吗? -
只有五个,但仍然无法帮助我发布它
-
我对json web servie不熟悉
标签: javascript html forms post