/    Sign up×
Community /Pin to ProfileBookmark

Newbie Student looking for assistance please

I’ve been at this for three days. I need to create a simple calculator and i’m having trouble. This HTML contains three textboxes, two for operands and
one for a result. four buttons one for each (+,-,*,/) using onclick to solve. ?

This what I have and it’s not working

[CODE]<html>
<form>

<table>
<tr><td>Operand 1</td><td><input type=”text” name=”op1″/></td></tr>
<tr><td>Operand 2</td><td><input type=”text” name=”op2″/></td></tr>
<tr><td>Result</td><td><input type=”text” name=”r”/></td></tr>
</table>
<input type=”button” value=”+” onClick=”do_addition()”/>
<input type=”button” value=”-” onClick=”do_subtraction()”/>
<input type=”button” value=”*” onClick=”do_multiplication()”/>
<input type=”button” value=”/” onClick=”do_division()”/>
</form>

<head>
<title>Homework 2</title>
<meta name=”author” content=”CV”/>
<script type=”text/javascript”>
function do_addition() {
op1=parsefloat(op1.value);
op2=parsefloat(op2.value);
rval=op1+op2;
r.value=rval;
}
function do_subtraction() {
op1=parsefloat(op1.value);
op2=parsefloat(op2.value);
rval=op1-op2;
r.value=rval;
}
function do_multiplication() {
op1=parsefloat(op1.value);
op2=parsefloat(op2.value);
rval=op1*op2;
r.value=rval;
}
function do_division() {
op1=parsefloat(op1.value);
op2=parsefloat(op2.value);
rval=op1/op2;
r.value=rval;
}
</script>

</head>
<body>
</body>

</html>[/CODE]

to post a comment
HTML

2 Comments(s)

Copy linkTweet thisAlerts:
@drhowarddrfineOct 15.2006 — You should ask this in the javascript forum.
Copy linkTweet thisAlerts:
@_Aerospace_Eng_Oct 15.2006 — Then they would just be cross posting. Check your function name that converts the numbers to floats. You problem lies there. Since you are a student I won't be telling you. Remember JS is case sensitive.
×

Success!

Help @browneyes 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...