JavaScript Calculator please help.
Hey guys.
I need to make a button that will display my name in the answer box of my calculator.
Can anyone please show me the code to do this?
Thank you very much.
Here is the code I have so far:
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("Hello Alex!");
}
</script>
<script type="text/javascript" src="http://moodle.viuonline.ca/lib/ufo.js"></script>
<link rel="stylesheet" type="text/css" href="http://moodle.viuonline.ca/theme/standard/styles.php" />
<link rel="stylesheet" type="text/css" href="http://moodle.viuonline.ca/theme/viuonline/styles.php" />
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function a_plus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a+b
form.ans.value = c
}
function a_minus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a-b
form.ans.value=c
}
function a_times_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a*b
form.ans.value=c
}
function a_div_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a/b
form.ans.value = c
}
function a_pow_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=Math.pow(a, b)
form.ans.value = c
}
// End -->
</SCRIPT>
</head>
<title> Java Assignment </title>
<body>
<center><input type="button" onclick="show_alert()" value="[click me if you dare]" /></center>
<CENTER>
<TABLE BORDER=5>
<TR>
<TD>
<FORM name="formx"><input type=text size=10 value=12 name="a">
<td>
<input type="button" value=" + " name=plus
onmouseover="plus.value='ADD'" onmouseout="plus.value='+'"
onClick="a_plus_b(this.form)">
<td>
<input type="button" value=" - " name=minus
onmouseover="minus.value='SUBTRACT'" onmouseout="minus.value='-'"
onClick="a_minus_b(this.form)">
<td>
<input type="button" value=" x " name=times
onmouseover="times.value='times'" onmouseout="times.value='X'"
onClick="a_times_b(this.form)">
<td>
<input type="button" value=" / " name=divide
onmouseover="divide.value='DIVIDE'" onmouseout="divide.value='/'"
onClick="a_div_b(this.form)">
<td>
<input type="button" value=" ^ " name=power
onmouseover="power.value='POW'" onmouseout="power.value='^'"
onClick="a_pow_b(this.form)">
<td>
<input type="number" size=4 value=3 name="b"> = <input type "number" value=0 name="ans" size=9>
</tr>
</td>
</FORM>
</CENTER>
</body>
</html>
Code:
<input type="button" onclick="document.formx.ans.value = 'alex';" value="name in answer box">
Don't use eval : use Number , parseInt or parseFloat
https://developer.mozilla.org/en/Cor...loat_Functions
At least 98% of internet users' DNA is identical to that of chimpanzees
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks