User Name Password Register
DaniWeb IT Discussion Community
All
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 374,580 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,315 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: 1658 | Replies: 4
Reply
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

setting value is not sticking

  #1  
Jul 18th, 2005
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.

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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: setting value is not sticking

  #2  
Jul 19th, 2005
It's impossible to tell with only the code you showed. Nothing in those two lines would cause the text to disappear.
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: setting value is not sticking

  #3  
Jul 19th, 2005
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>
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: setting value is not sticking

  #4  
Jul 19th, 2005
That's exactly what's happening, because of all your submit buttons. You are submitting the form... that's not what you want to do. Change all the "submit" to "button".
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: setting value is not sticking

  #5  
Jul 19th, 2005
THANK YOU so much. I would have never spotted or known what was happening.

Thanks for helping.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:33 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC