<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"><br>
<input type="button" name="Show" value="Show" onClick="ShowValue();">

</body>
</html>

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

Recommended Answers

All 2 Replies

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"><br>
<input type="button" name="Show" value="Show" onClick="ShowValue();">

</body>
</html>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.