By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

Writing a variable to an input field

P: 3
I'm a newbie to javascript, I will admit.
So any help would be much appreciated.

I've got a form to which I'm attempting to write a var into an input field.

here's some snippets

Expand|Select|Wrap|Line Numbers
  1. "document.Rate.saves.value = TotalS"
Expand|Select|Wrap|Line Numbers
  1. "<th>Saves:<input maxLength=3 size=5 name=TotalS>"
That should write, correct?

If so I'm probably not defining the var correctly... if you are willing to take a look at the script and tell me what I'm doing wrong, please let me know or contact me with the info in my profile.
Jun 16 '07 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
I'm a newbie to javascript, I will admit.
So any help would be much appreciated.

I've got a form to which I'm attempting to write a var into an input field.

here's some snippets

Expand|Select|Wrap|Line Numbers
  1. "document.Rate.saves.value = TotalS"
Expand|Select|Wrap|Line Numbers
  1. "<th>Saves:<input maxLength=3 size=5 name=TotalS>"
That should write, correct?

If so I'm probably not defining the var correctly... if you are willing to take a look at the script and tell me what I'm doing wrong, please let me know or contact me with the info in my profile.
Are you writing to the page using Javascript?
Jun 16 '07 #2

acoder
Expert Mod 15k+
P: 16,027
Changed thread title.

MODERATOR
Jun 16 '07 #3

acoder
Expert Mod 15k+
P: 16,027
How are you defining the variable, TotalS?
Jun 16 '07 #4

P: 3
Here's the javascript, the areas of the form that It's currently attempting to write to, and the buttons that should cue the script. I've had a friend give me a quick and simple explanation of how everything should work, but I've obviously not grasped it as much as I should've.

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=JavaScript>
  2.  
  3. var saves=0;
  4. function pluss() {
  5. saves++;
  6. window.status=saves;
  7. }
  8.  
  9. var disco=0;
  10. function plusd() {
  11. disco++;
  12. window.status=disco;
  13. }
  14.  
  15. var totalc = saves + disco
  16.  
  17. var rate = saves / totalc
  18.  
  19. var ratep = rate * 100
  20.  
  21. var nextt1 = totalc + 1
  22. var nextt2 = totalc + 2
  23. var nextt3 = totalc + 3
  24. var nexts1 = saves + 1
  25. var nexts2 = saves + 2
  26. var nexts3 = saves + 3
  27. var next1 = nexts1 / nextt1
  28. var next2 = nexts2 / nextt2
  29. var next3 = nexts3 / nextt3
  30. var nexty1 = next1 * 100
  31. var nexty2 = next2 * 100
  32. var nexty3 = next3 * 100
  33. var mint1 = totalc - 1
  34. var mint2 = totalc - 2
  35. var mint3 = totalc - 3
  36. var mins1 = saves - 1
  37. var mins2 = saves - 2
  38. var mins3 = saves - 2
  39. var nextd1 = mins1 / mint1
  40. var nextd2 = mins2 / mint2
  41. var nextd3 = mins3 / mint3
  42. var nextdp1 = nextd1 * 100
  43. var nextdp2 = nextd2 * 100
  44. var nextdp3 = nextd3 * 100
  45.  
  46. document.Rate.TotalC.value = totalc
  47. document.Rate.TotalS.value = saves
  48. </SCRIPT>
  49.  
Expand|Select|Wrap|Line Numbers
  1.                 <th>Calls Today: <input maxLength=3 size=5 name=TotalC></input></th>
  2.                 <th>Saves:<input maxLength=3 size=5 name=TotalS></input>  Discos:<input maxLength=3 size=5 name=TotalD></input></th>
  3.  
Expand|Select|Wrap|Line Numbers
  1.         <INPUT onclick = onClick=pluss() type=button value="Save">
  2.         <INPUT onClick = onClick=plusd() type=button value="Disco">
  3.         <INPUT name="Reset" type=reset onClick = onClick=Reset() value="Reset">
  4.  
What am I doing wrong?
Jun 16 '07 #5

P: 3
Issue solved.
I tied the buttons to the whole script individually as two separate functions. Undoubtedly this won't be my first or last newbie question here. thanks to those who tried to help me. :D
Jun 17 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.