•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,755 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,612 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1717 | Replies: 4
![]() |
| |
•
•
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation:
Rep Power: 9
Solved Threads: 18
I'm trying to make a simple calculator and whenever I want to add text to the textfield(say a number) it will show up, then will dissapear.
This is how I'm doing it, but why is the text dissapearing right after it appears?
Note: This method is called whenever one of the number buttons is clicked.
function display(number)
{
var x = document.form1.displayText;
x.value = number;
}This is how I'm doing it, but why is the text dissapearing right after it appears?
Note: This method is called whenever one of the number buttons is clicked.
•
•
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation:
Rep Power: 9
Solved Threads: 18
I know, that's what I don't understand. It' almost like it's refreshing the page or something. Here's the code I've got. I know the thing looks really ugly but I'm a beginner at javascript:
<html><head>
<title>JavaScript Calculator</title>
<script language="JavaScript" type="text/javascript">
function display(number)
{
var x = document.form1.displayText;
x.value = number;
}
</script>
</head>
<body>
<form name="form1">
<table>
<tr>
<input type="text" name="displayText" size="30">
</tr>
<tr>
<td><input type="submit" value="7" name="button7"
onClick="display('7')"></td>
<td><input type="submit" value="8" name="button8"
onClick="display(8)"></td>
<td><input type="submit" value="9" name="button9"
onClick="display(9)"></td>
<td><input type="submit" value="/" name="buttonDivide"></td>
<td><input type="submit" value="sqrt" name="buttonRoot"></td>
</tr>
<tr>
<td><input type="submit" value="4" name="button4"
onClick="display(4)"></td>
<td><input type="submit" value="5" name="button5"
onClick="display(5)"></td>
<td><input type="submit" value="6" name="button6"
onClick="display(6)"></td>
<td><input type="submit" value="*" name="buttonMultiply"></td>
<td><input type="submit" value="^2" name="buttonSquare"></td>
</tr>
<tr>
<td><input type="submit" value="1" name="button1"
onClick="display(1)"></td>
<td><input type="submit" value="2" name="button2"
onClick="display(2)"></td>
<td><input type="submit" value="3" name="button3"
onClick="display(3)"></td>
<td><input type="submit" value="-" name="buttonMinus"></td>
<td><input type="submit" value="1/x" name="buttonOneX"></td>
</tr>
<tr>
<td><input type="submit" value="0" name="button0"
onClick="display(0)"></td>
<td><input type="submit" value="." name="buttonPeriod"></td>
<td><input type="submit" value="+/-" name="buttonPlusOrMinus"></td>
<td><input type="submit" value="+" name="buttonPlus"></td>
<td><input type="submit" value="=" name="buttonEquals"></td>
</tr>
</table>
</form>
</body>
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- help setting up web server (Linux Servers and Apache)
- Setting up a 2nd hard drive (Windows NT / 2000 / XP / 2003)
- newbie: need help setting up my network, router + firewall problems (Networking Hardware Configuration)
- setting up a new network (Networking Hardware Configuration)
- Video setting question (Monitors, Displays and Video Cards)
- Setting up my PC as a web server (Windows NT / 2000 / XP / 2003)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Problem using onload
- Next Thread: Please i need some help with js



Hybrid Mode