943,879 Members | Top Members by Rank

Ad:
Apr 24th, 2006
0

Accessing Non-form Variables

Expand Post »
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type"content="text/html; charset=windows-1254">
  4. <title>JavaScript</title>
  5. </head>
  6. <body bgcolor="#000000" text="#ffffff" vlink="#99FF33" link="#FF99FF">
  7.  
  8. <script language="javascript">
  9. function ShowValue()
  10. {
  11. document.TextBox.value = "You clicked the button."; //Error on this line
  12. }
  13. </script>
  14.  
  15. <input type="text" name="TextBox" width="128"><br>
  16. <input type="button" name="Show" value="Show" onClick="ShowValue();">
  17.  
  18. </body>
  19. </html>
Text control doesn't show the text. Why doesn't it?
Similar Threads
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
AhmedHan is offline Offline
71 posts
since Apr 2005
Apr 24th, 2006
0

Re: Accessing Non-form Variables

For reasons that are beyond my understanding, we are being moved into the whole new era of having to give things ID's. If someone knows another way, simplier, using names, please let me know, but try this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type"content="text/html; charset=windows-1254">
  4. <title>JavaScript</title>
  5. <script language="javascript">
  6. function ShowValue()
  7. {
  8. document.getElementById("TextBox").value = "You clicked the button.";
  9.  
  10. }
  11. </script>
  12. </head>
  13. <body bgcolor="#000000" text="#ffffff" vlink="#99FF33" link="#FF99FF">
  14.  
  15.  
  16. <input type="text" ID="TextBox" name="TextBox" width="128"><br>
  17. <input type="button" name="Show" value="Show" onClick="ShowValue();">
  18.  
  19. </body>
  20. </html>
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Apr 24th, 2006
0

Re: Accessing Non-form Variables

Well, you don't show any DOCTYPE, so we, and your browser, have no idea of which Document Object Model to use. "document.Textbox" may or may not be meaningful in any particular browser's default HTML version/DOM.

You simply must declare a proper DOCTYPE, and then work within that Object Model.

Both "document.getElementById()" and "document.getElementByName()" are perfectly valid methods within their DOMs.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Help w (document.lastModified)
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: JavaScript for uploading images to website





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC