setting value is not sticking

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

setting value is not sticking

 
0
  #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.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function display(number)
  2. {
  3. var x = document.form1.displayText;
  4. x.value = number;
  5. }

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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: setting value is not sticking

 
0
  #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 Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: setting value is not sticking

 
0
  #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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html><head>
  2. <title>JavaScript Calculator</title>
  3. <script language="JavaScript" type="text/javascript">
  4. function display(number)
  5. {
  6. var x = document.form1.displayText;
  7. x.value = number;
  8. }
  9. </script>
  10. </head>
  11. <body>
  12. <form name="form1">
  13. <table>
  14. <tr>
  15. <input type="text" name="displayText" size="30">
  16. </tr>
  17. <tr>
  18. <td><input type="submit" value="7" name="button7"
  19. onClick="display('7')"></td>
  20. <td><input type="submit" value="8" name="button8"
  21. onClick="display(8)"></td>
  22. <td><input type="submit" value="9" name="button9"
  23. onClick="display(9)"></td>
  24. <td><input type="submit" value="/" name="buttonDivide"></td>
  25. <td><input type="submit" value="sqrt" name="buttonRoot"></td>
  26. </tr>
  27. <tr>
  28. <td><input type="submit" value="4" name="button4"
  29. onClick="display(4)"></td>
  30. <td><input type="submit" value="5" name="button5"
  31. onClick="display(5)"></td>
  32. <td><input type="submit" value="6" name="button6"
  33. onClick="display(6)"></td>
  34. <td><input type="submit" value="*" name="buttonMultiply"></td>
  35. <td><input type="submit" value="^2" name="buttonSquare"></td>
  36. </tr>
  37. <tr>
  38. <td><input type="submit" value="1" name="button1"
  39. onClick="display(1)"></td>
  40. <td><input type="submit" value="2" name="button2"
  41. onClick="display(2)"></td>
  42. <td><input type="submit" value="3" name="button3"
  43. onClick="display(3)"></td>
  44. <td><input type="submit" value="-" name="buttonMinus"></td>
  45. <td><input type="submit" value="1/x" name="buttonOneX"></td>
  46. </tr>
  47. <tr>
  48. <td><input type="submit" value="0" name="button0"
  49. onClick="display(0)"></td>
  50. <td><input type="submit" value="." name="buttonPeriod"></td>
  51. <td><input type="submit" value="+/-" name="buttonPlusOrMinus"></td>
  52. <td><input type="submit" value="+" name="buttonPlus"></td>
  53. <td><input type="submit" value="=" name="buttonEquals"></td>
  54. </tr>
  55. </table>
  56. </form>
  57. </body>
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: setting value is not sticking

 
0
  #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 Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: setting value is not sticking

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

Thanks for helping.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC