Accessing Non-form Variables

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

Join Date: Apr 2005
Posts: 71
Reputation: AhmedHan is an unknown quantity at this point 
Solved Threads: 1
AhmedHan's Avatar
AhmedHan AhmedHan is offline Offline
Junior Poster in Training

Accessing Non-form Variables

 
0
  #1
Apr 24th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Accessing Non-form Variables

 
0
  #2
Apr 24th, 2006
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>
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: Accessing Non-form Variables

 
0
  #3
Apr 24th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC