2017-04-25 89 views
0

某些內容阻止了「計算支付」按鈕的顯示。我之前做過類似的問題,並使用相似的代碼行來顯示按鈕,所以我很困惑它爲什麼現在不工作。另外,還有一些我無法弄清楚的錯誤,教授沒有反應。基本JavaScript/HTML代碼問題

<!DOCTYPE> 
<html> 
<head> 
<title> Internet Service Costs </title> 

<script> 
function computeAmtDue(){ 
    var amountDue; 


    if (document.getElementById(‘Year10’).checked){ 
     amountDue = 12.95 +((document.getElementById(‘hours’) - 10) * 4.00); 
    if (document.getElementById(‘Nonprofit’).checked){ 
     amountDue *=.80; 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
    } else { 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
    } 
} else if (document.getElementById(‘Year20’).checked) { 
    amountDue = 14.95 +((document.getElementById(‘hours’) - 20) * 2.00); 
    if (document.getElementById(‘Nonprofit’).checked){ 
     amountDue *=.80; 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
    } else { 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
    } 
} else if (document.getElementById(‘Year30’).checked){ 
    amountDue = 20.00 +((document.getElementById(‘hours’) - 30) * 1.00); 
    if (document.getElementById(‘Nonprofit’).checked){ 
     amountDue *=.80; 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
    } else { 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
    } 
} else if (document.getElementById(‘YearUnl’).checked){ 
    amountDue = 35.95; 
    if (document.getElementById(‘Nonprofit’).checked){ 
     amountDue *=.80; 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
    } else { 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
    } 
    } 
} 


</script> 
</head> 

<body> 
<h1> Internet Service Costs </h1> 

<form name=「InternetPmt」> 

    <input type="radio" name=「Package」 value="10" id=「Year10」 />Package A<br> 
    <input type="radio" name=「Package」 value=「20」 id=「Year20」 />Package B<br> 
    <input type="radio" name=「Package」 value="30" id=「Year30」 />Package C<br> 
    <input type="radio" name=「Package」 value="" id=「YearUnl」 />Package D<br> 
<br> 

    <input type="checkbox" name=「NonprofitOrg」 value=「Nonprofit「 id=「Nonprofit」> 
Nonprofit Organization<br> 

    <p> Hours Used:<input type="text" name=「Hours」 value="" id=「hours」 /> </p> 

    Total Amount Due: 
    <input type=「text」 name=「AmtDue」 value="" /><br><br> 
    <input type=「button」 value=「Compute Monthly」 name=「btnCompute」 
onclick=「computeAmtDue()」/> 

</form> 
</body> 
</html> 
+0

控制檯的響應,但... – Teemu

+1

^學會使用控制檯,你有語法錯誤。 – adeneo

+0

你可以用快速撥號器打開這個... –

回答

0

更換所有‘ ’' '‘‘ ’’" ",你忘了加上.valuegetElementById檢查它,它的工作原理。

function computeAmtDue(){ 
 
    var amountDue; 
 

 
    if (document.getElementById('Year10').checked){ 
 
     amountDue = 12.95 +((document.getElementById('hours').value - 10) * 4.00); 
 
    if (document.getElementById('Nonprofit').checked){ 
 
     amountDue *=.80; 
 
     console.log(amountDue); 
 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
 
    } else { 
 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
 
     console.log(amountDue); 
 
    } 
 
} else if (document.getElementById('Year20').checked) { 
 
    amountDue = 14.95 +((document.getElementById('hours').value - 20) * 2.00); 
 
    if (document.getElementById('Nonprofit').checked){ 
 
     amountDue *=.80; 
 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
 
    } else { 
 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
 
    } 
 
} else if (document.getElementById('Year30').checked){ 
 
    amountDue = 20.00 +((document.getElementById('hours').value - 30) * 1.00); 
 
    if (document.getElementById('Nonprofit').checked){ 
 
     amountDue *=.80; 
 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
 
    } else { 
 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
 
    } 
 
} else if (document.getElementById('YearUnl').checked){ 
 
    amountDue = 35.95; 
 
    if (document.getElementById('Nonprofit').checked){ 
 
     amountDue *=.80; 
 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
 
    } else { 
 
     document.InternetPmt.AmtDue.value = amountDue.toFixed(2); 
 
    } 
 
    } 
 
}
<h1> Internet Service Costs </h1> 
 

 
<form name="InternetPmt"> 
 

 
    <input type="radio" name="Package" value="10" id="Year10" />Package A<br> 
 
    <input type="radio" name="Package" value="20" id="Year20" />Package B<br> 
 
    <input type="radio" name="Package" value="30" id="Year30" />Package C<br> 
 
    <input type="radio" name="Package" value="" id="YearUnl" />Package D<br> 
 
<br> 
 

 
    <input type="checkbox" name="NonprofitOrg" value="Nonprofit" id="Nonprofit"> 
 
Nonprofit Organization<br> 
 

 
    <p> Hours Used:<input type="text" name="Hours" value="" id="hours" /> </p> 
 

 
    Total Amount Due: 
 
    <input type="text" name="AmtDue" value="" /><br><br> 
 
    <input type="button" value="Compute Monthly" name="btnCompute" 
 
onclick="computeAmtDue()"/> 
 

 
</form>