The following script function "btnRunScript_onclick" works as long as it does not access the HTML control "txtMessage". If it does, "Page Error" is shown in the statusbar of Internet Explorer (6). Knows anybody why? Thank you.

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="GuessingGame.aspx.vb" Inherits="Ch07Le04.GuessingGame"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="">
<script id="clientEventHandlersJS" language="javascript">

function btnRunScript_onclick() {
        sMessage = "ABC";
	/* document.write("<h2>ABC</h2>"); */ /* works */
	txtMessage.value = sMessage; /* raises Page Error */

<body language="javascript">
<form id="Form1" method="post" runat="server">
<h2>The Guessing Game - Responding to Events with Script Procedures</h2>
<INPUT id="btnRunScript" type="button" value="Run Script" language="javascript" onclick="return btnRunScript_onclick()">
<P><INPUT id="txtMessage" type="text" value="ABC" name="txtMessage"></P>

I enabled "detect scripterrors" in the browser. The message is:
'txtMessage' is not defined.
I moved the <script> element behind the <body> element. But this page error is still raised.

I solved the problem meanwhile. I replaced

txtMessage.value = sMessage; /* raises Page Error */


window.Form1.txtMessage.value = sMessage; /* works */
Be a part of the DaniWeb community

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