/    Sign up×
Community /Pin to ProfileBookmark

Input boxes/Calc function

Hello All,

I’m doing an assignment to make input boxes where I can perform different functions like adding, subtracting, multiplying, dividing, modulus, and isEven.

Here is the javascript I wrote for addition:

<SCRIPT language = JavaScript>
function calculate() {
A = document.frmOne.txtFirstNumber.value
B = document.frmOne.txtSecondNumber.value
A = Number(A)
B = Number(?
C = (A + ?
document.frmOne.txtThirdNumber.value = C
}
</script>

and in the html:

<FORM NAME = frmOne>
Number One:
<INPUT TYPE = Text NAME = txtFirstNumber SIZE = 5 value =””>
Number Two:
<INPUT TYPE = Text NAME = txtSecondNumber SIZE = 5 value =””>
<P> Total:
<INPUT TYPE = Text NAME = txtThirdNumber SIZE = 5 value = “”>
<P>
<Input Type = Button NAME = b1 VALUE = “Add Numbers” onClick = calculate()>
</FORM>

If anyone can point me in the right direction, I would appreciate it.:rolleyes: I think I’m not understanding the similar code in the function javascript and the html code to activate the function. Any help/advice would be great?

Thanks
?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@brenz_netFeb 24.2010 — By simply putting your script code before the ending HEAD tag, and putting your form in between the BODY tags, this seems to work fine in IE and FF. Although I would suggest paying more attention to consistency - i.e., quote all paramaters, end script statements with ;, etc...

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<SCRIPT language = JavaScript>
function calculate() {
A = document.frmOne.txtFirstNumber.value
B = document.frmOne.txtSecondNumber.value
A = Number(A)
B = Number(B)
C = (A + B)
document.frmOne.txtThirdNumber.value = C
}
</script>

</head>

<body>
<FORM NAME = frmOne>
Number One:
<INPUT TYPE = Text NAME = txtFirstNumber SIZE = 5 value ="">
Number Two:
<INPUT TYPE = Text NAME = txtSecondNumber SIZE = 5 value ="">
<P> Total:
<INPUT TYPE = Text NAME = txtThirdNumber SIZE = 5 value = "">
<P>
<Input Type = Button NAME = b1 VALUE = "Add Numbers" onClick = calculate()>
</FORM>

</body>
</html>
[/CODE]
×

Success!

Help @ron11612002 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.24,
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,
)...