Script raises Page error when accessing HTML control

Thread Solved

Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Script raises Page error when accessing HTML control

 
0
  #1
Jun 13th, 2008
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.
  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>
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: Script raises Page error when accessing HTML control

 
0
  #2
Jun 13th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: Script raises Page error when accessing HTML control

 
0
  #3
Jun 13th, 2008
I solved the problem meanwhile. I replaced

  1. txtMessage.value = sMessage; /* raises Page Error */
by
  1. window.Form1.txtMessage.value = sMessage; /* works */
Last edited by dadelsen; Jun 13th, 2008 at 12:51 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum


Views: 1049 | Replies: 2
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC