我正在设计一个Paypal表格,基本价格为2979美元。现在我的表单中有复选框和下拉列表。可以选择多个复选框。在选中复选框时,具有单独复选框的价格将添加到基本价格中。同样的下拉列表。
我的问题是我可以将复选框值添加到基本价格,但下拉价格未正确设置。我想它总数会增加两倍。
请帮我解决这个问题。
请在下面找到我的javascript代码和HTML代码: -
<SCRIPT type=text/javascript>
<!--
function Dollar (val) { // force to valid dollar amount
var str,pos,rnd=0;
if (val < .995) rnd = 1; // for old Netscape browsers
str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape
pos = str.indexOf (".");
if (pos > 0) str = str.substring (rnd, pos + 3);
return str;
}
var validateDropdown=0;
var dropdownVal;
function validate()
{
validateDropdown=0;
var ddl = document.getElementById("DropDown");
var selectedValue = ddl.options[ddl.selectedIndex].value;
if (selectedValue != "Upgrade laptop")
{
validateDropdown=1;
dropdownVal=selectedValue;
}
else
{
validateDropdown=0;
}
}
function ReadForm (obj1, tst)
{ // process radio and checkbox
var i,j,amt=0,amt1=0,des="",obj,pos,val,tok,tag,finalamt=0,
op1a="",op1b="",op2a="",op2b="",itmn="";
var ary = new Array ();
if (obj1.baseamt) amt = obj1.baseamt.value*1.0; // base amount
if (obj1.basedes) des = obj1.basedes.value; // base description
if (obj1.baseon0) op1a = obj1.baseon0.value; // base options
if (obj1.baseos0) op1b = obj1.baseos0.value;
if (obj1.baseon1) op2a = obj1.baseon1.value;
if (obj1.baseos1) op2b = obj1.baseos1.value;
if (obj1.baseitn) itmn = obj1.baseitn.value;
validate();
for (i=0; i<obj1.length; i++)
{ // run entire form
obj = obj1.elements[i]; // a form element
if (obj.type == "checkbox" || // checkboxes
obj.type == "radio")
{ // and radios
//..................................................... one set..............................................
if (obj.checked)
{ // did user check it?
val = obj.value; // the value of the selection
ary = val.split (" "); // break apart
for (j=0; j<ary.length; j++)
{ // look at all items
// first we do single character tokens...
if (ary[j].length < 2) continue;
tok = ary[j].substring (0,1); // first character
val = ary[j].substring (2); // get data
if (tok == "@") amt = val * 1.0;
if (tok == "+") amt = amt + val*1.0;
if (tok == "%") amt = amt + (amt * val/100.0);
if (tok == "#")
{ // record item number
if (obj1.item_number) obj1.item_number.value = val;
ary[j] = ""; // zap this array element
}
}
val = ary.join (" "); // rebuild val with what's left tag = obj.name.substring (obj.name.length-2); // get flag
if (tag == "1a") op1a = op1a + " " + val;
else if (tag == "1b") op1b = op1b + " " + val;
else if (tag == "2a") op2a = op2a + " " + val;
else if (tag == "2b") op2b = op2b + " " + val;
else if (tag == "3i") itmn = itmn + " " + val;
else if (des.length == 0) des = val;
else des = des + ", " + val;
}
//..................................................... one set..............................................
//..................................................... one set..............................................
if (validateDropdown==1)
{ // did user check it?
val = dropdownVal; // the value of the selection
ary = val.split (" "); // break apart
for (j=0; j<ary.length; j++)
{ // look at all items
// first we do single character tokens...
if (ary[j].length < 2) continue;
tok = ary[j].substring (0,1); // first character
val = ary[j].substring (2); // get data
if (tok == "@") amt = val * 1.0;
if (tok == "+") amt = amt + val*1.0;
if (tok == "%") amt = amt + (amt * val/100.0);
if (tok == "#")
{ // record item number
if (obj1.item_number) obj1.item_number.value = val;
ary[j] = ""; // zap this array element
}
}
}
//..................................................... one set..............................................
}
}
// Now summarize stuff we just processed, above
if (op1a.length > 0) obj1.on0.value = op1a;
if (op1b.length > 0) obj1.os0.value = op1b;
if (op2a.length > 0) obj1.on1.value = op2a;
if (op2b.length > 0) obj1.os1.value = op2b;
if (itmn.length > 0) obj1.item_number.value = itmn;
obj1.item_name.value = des;
obj1.amount.value = Dollar (amt);
if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
}
//-->
</SCRIPT>
整个表单可以从这里下载: - http://prminfotech.com/test.html
请帮助我。