/    Sign up×
Community /Pin to ProfileBookmark

Why doesn’t this script button work?

Could someone help me by explaining why the second button in the script below doesn’t work? I just wanted to use my own image instead of the default. Many thanks for any help.

<input type=”button” name=”Button” value=”Calculate Repayment” onclick=”CalcRepay()” class=”BodyText”>
<input name=”Button” type=”image” src=”images/calculate.gif” border=”0″ value=”Calculate Repayment” onclick=”CalcRepay()”class=”BodyText”>

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@Stopper31Apr 08.2004 — Don't know why it doesn't work... I copied your code into this simple HTML doc and it worked for me!

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script language="Javascript"&gt;
function CalcRepay()
{
alert ("function hit")
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;input type="button" name="Button" value="Calculate Repayment" onclick="CalcRepay()" class="BodyText"&gt;
&lt;input name="Button" type="image" src="sample.gif" border="0" value="Calculate Repayment"

onclick="CalcRepay()"class="BodyText"&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@LanceauthorApr 08.2004 — Yeah, the button seems to work and perform the calculation on the script below but then the result quickly disappears whereas on the original default button the calculation remains. Sorry, I thought the snippet of code on my original post was enough info. Many thanks for helping me.

Cheers

Lance
Copy linkTweet thisAlerts:
@LanceauthorApr 08.2004 — <html>

<head>

<title>Webster's Finance Calculator</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language=javascript>

<!--

var loc=31;loc2=5;

function checkEnter(pfield, pname)

{

var field = pfield.value

var msg

var status = true

if (field.length == 0)

{

msg = "The " + pname + " field must be entered."

alert(msg)

status = false

}

return status

}

function checkNumb(pnumb, pname)

{

var numb = pnumb.value

var message

var indx

var status = false

for (var indx = 0; indx < numb.length; indx++)

{

if (numb.charAt(indx) >= "0" && numb.charAt(indx) <= "9")

{

status = true

}

}

for (var indx = 0; indx < numb.length; indx++)

{

if (!((numb.charAt(indx) >= "0" && numb.charAt(indx) <= "9") ||

numb.charAt(indx) == " " ||

numb.charAt(indx) == "." ||

numb.charAt(indx) == ","))

{

status = false

}

}

if (!status)

{

msg = "The " + pname + " field must be a number."

alert(msg)

}

return status

}

function parseNumb(pnumbstr)

{

var numb = pnumbstr.value

var indx

indx = numb.indexOf(",")

while (indx != -1)

{

numb = numb.substring(0,indx) + numb.substring(indx*1 + 1,numb.length)

indx = numb.indexOf(",")

}

indx = numb.indexOf(" ")

while (indx != -1)

{

numb = numb.substring(0,indx) + numb.substring(indx*
1 + 1,numb.length)

indx = numb.indexOf(" ")

}

return numb

}

function parseMonth(pyear, pmonth)

{

var year = parseNumb(pyear)

var month = parseNumb(pmonth)

var period

var indx

period = Math.ceil(month*1 + year*12)

return period

}

function checkLoan(pLoan)

{

var LoanAmt = pLoan

var status

if (checkEnter(LoanAmt,"Loan Amount"))

{

status = checkNumb(LoanAmt,"Loan Amount")

}

return status

}

function checkRepay(pRepay)

{

var RepayAmt = pRepay

var status = true

if (checkEnter(RepayAmt,"Repay Amount"))

{

if (checkNumb(RepayAmt,"Repay Amount"))

{

if (RepayAmt.value == 0)

{

alert("The Repay Amount can not be zero.")

status = false

}

}

else

{

status = false

}

}

else

{

status = false

}

return status

}

function checkIntRate(pIntRate)

{

var IntRate = pIntRate

var status = true

if (checkEnter(IntRate,"Interest Rate"))

{

if (checkNumb(IntRate,"Interest Rate"))

{

if (IntRate.value == 0)

{

alert("The Interest Rate can not be zero.")

status = false

}

}

else

{

status = false

}

}

else

{

status = false

}

return status

}

function checkTermY(pYear)
Copy linkTweet thisAlerts:
@Stopper31Apr 08.2004 — So have you gotten it to work? If not, post your entire code so I can see it!

Edit: You beat me to the punch!!
Copy linkTweet thisAlerts:
@LanceauthorApr 08.2004 — {

var TermYear = pYear

var status = true

if (checkEnter(TermYear,"Year Period"))

{

if (checkNumb(TermYear,"Year Period"))

{

if (TermYear.value > 30)

{

alert("The Year Period can not be longer than 30 years.")

status = false

}

}

else

{

status = false

}

}

else

{

status = false

}

return status

}

function checkTermM(pMonth)

{

var TermMonth = pMonth

var status = true

if (checkEnter(TermMonth,"Month Period"))

{

if (checkNumb(TermMonth,"Month Period"))

{

if (TermMonth.value > 11)

{

alert("Please use the Year field to enter a period longer than 11 months.")

status = false

}

}

else

{

status = false

}

}

else

{

status = false

}

return status

}

function CalcRepayAmt(pLoanAmt, pIntRate, pTerm)

{

var RepayAmt

RepayAmt = pLoanAmt * pIntRate/(1 - Math.pow((1 + pIntRate*1),-pTerm))

RepayAmt = Math.ceil(RepayAmt)

return RepayAmt

}

function CalcRepay()

{

var LoanAmount

var InterestRate

var MonthTerm

if (checkLoan(document.repay.LoanAmt1) &&

checkIntRate(document.repay.IntRate1) &&

checkTermY(document.repay.TermYear1) &&

checkTermM(document.repay.TermMonth1))

{

LoanAmount = parseNumb(document.repay.LoanAmt1)

InterestRate = parseNumb(document.repay.IntRate1)/1200

MonthTerm = parseMonth(document.repay.TermYear1,document.repay.TermMonth1)

document.repay.RepayAmt1.value = CalcRepayAmt(LoanAmount, InterestRate, MonthTerm)

}

else

{

document.repay.RepayAmt1.value = " "

}

}

function CalcTerm()

{

var MonthTerm = 0

var YearTerm = 0

var MaxTerm = 30 * 12

var LoanAmount

var RepayAmount

var InterestRate

var MinRepay

if (checkLoan(document.repay.LoanAmt2) &&

checkRepay(document.repay.RepayAmt2) &&

checkIntRate(document.repay.IntRate2))

{

LoanAmount = parseNumb(document.repay.LoanAmt2)

RepayAmount = parseNumb(document.repay.RepayAmt2)

InterestRate = parseNumb(document.repay.IntRate2)/1200

MinRepay = CalcRepayAmt(LoanAmount, InterestRate, MaxTerm)

if (RepayAmount < MinRepay)

{

Msg = "Sorry, the minimum repayment amount must be " + MinRepay + " dollars."

alert(Msg)

document.repay.TermYear2.value = " "

document.repay.TermMonth2.value = " "

}

else

{

MonthTerm = Math.log(RepayAmount/(RepayAmount - LoanAmount *
InterestRate)) / Math.log(1 + InterestRate)

MonthTerm = Math.ceil(MonthTerm)

YearTerm = Math.floor(MonthTerm / 12)

MonthTerm = MonthTerm - (YearTerm * 12)

document.repay.TermYear2.value = YearTerm

document.repay.TermMonth2.value = MonthTerm

}

}

else

{

document.repay.TermYear2.value = " "

document.repay.TermMonth2.value = " "

}

}

function CalcLoan()

{

var LoanAmt

var RepayAmount

var InterestRate

var MonthTerm

if (checkRepay(document.repay.RepayAmt3) &&

checkIntRate(document.repay.IntRate3) &&

checkTermY(document.repay.TermYear3) &&

checkTermM(document.repay.TermMonth3))

{

RepayAmount = parseNumb(document.repay.RepayAmt3)

InterestRate = parseNumb(document.repay.IntRate3)/1200

MonthTerm = parseMonth(document.repay.TermYear3,document.repay.TermMonth3)

LoanAmt = RepayAmount *
(1 - Math.pow((1 + InterestRate*1),-MonthTerm))/InterestRate

document.repay.LoanAmt3.value = Math.floor(LoanAmt)

}

else

{

document.repay.LoanAmt3.value = " "

}

}

// -->

function close_window() {

window.close();

}

//-->

</script>

</head>

<body bgcolor="#EEEEEE" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<div align="center">

<form name="repay">

<table width="400" border=0 cellpadding=5 cellspacing=0>

<tr bgcolor="#CCCCCC">

<td align=left nowrap class="SubTitles2">&nbsp;</td>

<td align=left nowrap class="SubTitles2"><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">Loan Amount:</font></strong></td>

<td class="TinyText"><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">$</font></strong></td>

<td><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">

<input size="12" name="LoanAmt1" onBlur="checkLoan(LoanAmt1)" class="BodyText">

</font></strong></td>

<td>&nbsp;</td>

</tr>

<tr>

<td width="20" align=left nowrap class="SubTitles2">&nbsp;</td>

<td nowrap align=left class="SubTitles2"><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">Annual Interest Rate:</font></strong></td>

<td><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></strong></td>

<td class="TinyText"><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">

<input size="4" name="IntRate1" value="10.5" onBlur="checkIntRate(IntRate1)" class="BodyText">

%</font></strong></td>

<td class="TinyText">&nbsp;</td>

</tr>

<tr bgcolor="#CCCCCC">

<td align=left nowrap class="SubTitles2">&nbsp;</td>

<td align=left nowrap class="SubTitles2"><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">Repayment Period:</font></strong></td>

<td><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></strong></td>

<td nowrap class="TinyText"><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">

<input size="3" name="TermYear1" value="5" onBlur="checkTermY(TermYear1)" class="BodyText">

Years

<input size="2" name="TermMonth1" value="0" onBlur="checkTermM(TermMonth1)" class="BodyText">

Months</font></strong></td>

<td nowrap class="TinyText">&nbsp;</td>

</tr>

<tr>

<td nowrap align=left class="SubTitles2">&nbsp;</td>

<td nowrap align=left class="SubTitles2"><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">Monthly Repayment:</font></strong></td>

<td class="TinyText"><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">$</font></strong></td>

<td><strong><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">

<input size="8" name="RepayAmt1" class="BodyText">

</font></strong></td>

<td width="20">&nbsp;</td>

</tr>

<tr bgcolor="#CCCCCC">

<td colspan=5 align=center nowrap><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">

<input type="button" name="Button" value="Calculate Repayment" onclick="CalcRepay()" class="BodyText">

<input name="Button" type="image" src="images/calculate.gif" border="0" value="Calculate Repayment" onclick="CalcRepay()"class="BodyText">

</font></strong></td>

</tr>

</table>

</form>

<p><a href="javascript:;" onClick="close_window()"><img src="images/close.gif" width="100" height="20" border="0"></a></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</div>

</body>

</html>
Copy linkTweet thisAlerts:
@Stopper31Apr 08.2004 — You could try changing the line of code creating the image to:

<img src="sample.gif" name="Button" border="0" onclick="CalcRepay()" class="BodyText">

That seemed to work, the only thing you'll have to look into is the cursor over the image.
Copy linkTweet thisAlerts:
@LanceauthorApr 08.2004 — Thanks for all your help Stopper31. I'll have a look into the cursor problem. Not a big deal though, it'll still get clicked on.

Cheers

Lance
Copy linkTweet thisAlerts:
@Stopper31Apr 08.2004 — No problem, glad I could help!!
×

Success!

Help @Lance spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...