2016-03-04 63 views
-1

我有點困惑於在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; 

} 
+1

請定義「不再有效」。另外請注意,所有瀏覽器都不贊成通過'document'直接引用元素,並且在某些瀏覽器中可能會過時。 – Teemu

+0

'客戶= {文本1,Lname,添加,城市,StPrv,Cntry,Hphn,Wphn};'這是無效的語法,你檢查你的JS控制檯的錯誤? –

回答

0

也許你應該叫getCustomerList();buttonandchecks();方法中。類似這樣的:

function formSubmit() { 
    buttonandchecks(); 
    getCustomerList(); 
}