我对onClick中的两个函数以及如何使其正常工作感到有些困惑。它仅在使用一个函数时有效,但在有两个" getCustomerList()"不再有效。任何帮助将不胜感激。以下是相关代码:
HTML:
<form name="registration" action="registration.html" onsubmit="return validateForm()" method="post">
...
...
<input type="submit" value="Submit" onClick="buttonandchecks(); getCustomerList(); return false">
</form>
<h2>Customer Attributes:</h2>
<br>
<h3> <span id ="currentList"></span>
</h3>
JAVASCRIPT:
function buttonandchecks()
{
var x;
var output="";
var resultoutput="";
var extra=parseFloat(0);
var radio_value;
var total=parseInt(0);
for(x=0;x<document.costEstimation.special.length;x++)
{
if(document.costEstimation.special[x].checked)
{
radio_value=document.costEstimation.special[x].value;
}
}
radio_value=parseFloat(radio_value);
if(document.costEstimation.AC.checked)
{
extra+=10;
output=(output+" A/C");
}
if(document.costEstimation.WB.checked)
{
extra+=100;
output=(output+" Brakes");
}
if(document.costEstimation.CC.checked)
{
extra+=20;
output=(output+" Cruise Control");
}
if(document.costEstimation.BS.checked)
{
extra+=30;
output=(output+" Baby Seat");
}
total=radio_value+extra;
resultoutput=("Total: " + total.toFixed(2)+ " \nIncluding Extras: " + output);
alert(resultoutput);
}
function getCustomerList () {
var customer={Text1,Lname,Add,City,StPrv,Cntry,Hphn,Wphn};
var i=0;
var thisList="";
customer.Text1=document.getElementById("Text1").value;
customer.Lname=document.getElementById("Lname").value;
customer.Add=document.getElementById("Add").value;
customer.City=document.getElementById("City").value;
customer.StPrv=document.getElementById("StPrv").value;
customer.Cntry=document.getElementById("Cntry").value;
customer.Hphn=document.getElementById("Hphn").value;
customer.Wphn=document.getElementById("Wphn").value;
customerList.push(customer);
for(i=0; i< customerList.length;i++)
{
var thisCustomer={Text1,Lname,Add,City,StPrv,Cntry,Hphn,Wphn};
thisCustomer=customerList[i];
thisList+=thisCustomer.Text1 + " , "+thisCustomer.Lname+" , "+thisCustomer.Add+" , "+thisCustomer.City+" , "+thisCustomer.StPrv+" , "+thisCustomer.Cntry+" , "+thisCustomer.Hphn+" , "+thisCustomer.Wphn;
thisList+="<br>";
}
document.getElementById("currentList").innerHTML=thisList;
}
答案 0 :(得分:0)
也许您应该从getCustomerList();
方法中拨打buttonandchecks();
。像这样:
function formSubmit() {
buttonandchecks();
getCustomerList();
}