943,745 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 1303
  • ASP.NET RSS
Jun 13th, 2008
0

Script raises Page error when accessing HTML control

Expand Post »
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.
ASP.NET Syntax (Toggle Plain Text)
  1. <%@ Page Language="vb" AutoEventWireup="false" Codebehind="GuessingGame.aspx.vb" Inherits="Ch07Le04.GuessingGame"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  3. <HTML>
  4. <HEAD>
  5. <title>GuessingGame</title>
  6. <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
  7. <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
  8. <meta name="vs_defaultClientScript" content="JavaScript">
  9. <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  10. <script id="clientEventHandlersJS" language="javascript">
  11.  
  12. function btnRunScript_onclick() {
  13. sMessage = "ABC";
  14. /* document.write("<h2>ABC</h2>"); */ /* works */
  15. txtMessage.value = sMessage; /* raises Page Error */
  16. }
  17.  
  18. </script>
  19. </HEAD>
  20. <body language="javascript">
  21. <form id="Form1" method="post" runat="server">
  22. <h2>The Guessing Game - Responding to Events with Script Procedures</h2>
  23. <hr>
  24. <P>
  25. <INPUT id="btnRunScript" type="button" value="Run Script" language="javascript" onclick="return btnRunScript_onclick()">
  26. </P>
  27. <P><INPUT id="txtMessage" type="text" value="ABC" name="txtMessage"></P>
  28. </form>
  29. </body>
  30. </HTML>
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007
Jun 13th, 2008
0

Re: Script raises Page error when accessing HTML control

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.
Last edited by dadelsen; Jun 13th, 2008 at 12:24 pm.
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007
Jun 13th, 2008
0

Re: Script raises Page error when accessing HTML control

I solved the problem meanwhile. I replaced

ASP.NET Syntax (Toggle Plain Text)
  1. txtMessage.value = sMessage; /* raises Page Error */
by
ASP.NET Syntax (Toggle Plain Text)
  1. window.Form1.txtMessage.value = sMessage; /* works */
Last edited by dadelsen; Jun 13th, 2008 at 12:51 pm.
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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 ASP.NET Forum Timeline: Gis
Next Thread in ASP.NET Forum Timeline: Is there a way?





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


Follow us on Twitter


© 2011 DaniWeb® LLC