954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Accessing Non-form Variables

<html>
<head>
	<meta http-equiv="Content-Type"content="text/html; charset=windows-1254">
	<title>JavaScript</title>
</head>
<body bgcolor="#000000" text="#ffffff" vlink="#99FF33" link="#FF99FF">

<script language="javascript">
	function ShowValue()
	{
		document.TextBox.value = "You clicked the button."; //Error on this line
	}
</script>

<input type="text" name="TextBox" width="128">
<input type="button" name="Show" value="Show" onClick="ShowValue();">

</body>
</html>

Text control doesn't show the text. Why doesn't it?

AhmedHan
Junior Poster in Training
71 posts since Apr 2005
Reputation Points: 13
Solved Threads: 1
 

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:

<html>
<head>
	<meta http-equiv="Content-Type"content="text/html; charset=windows-1254">
	<title>JavaScript</title>
	<script language="javascript">
	function ShowValue()
	{
		document.getElementById("TextBox").value = "You clicked the button."; 	

	}
	</script>
</head>
<body bgcolor="#000000" text="#ffffff" vlink="#99FF33" link="#FF99FF">


<input type="text" ID="TextBox" name="TextBox" width="128">
<input type="button" name="Show" value="Show" onClick="ShowValue();">

</body>
</html>
Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

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.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You