Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

theForm is undefined - in place javascript error

Status
Not open for further replies.

Isadore

Technical User
Feb 3, 2002
2,167
US
This error is an auto-generated JavaScript function __doPostBack inserted by ASP.NET indicating that "theForm" was undefined. After much searching around I figured out I had left out the initial body tag which rectified the issue.

Another remedy if the <body> tags are in position is to declare the form's id in the body tag, e.g.,
<body onload="javascript: theForm = document.forms[0];">

The following code can be placed in the PreRender event of the custom filebrowsers page if the latter 2 options do not work.

Code:
Me.ClientScript.RegisterClientScriptBlock(Me.GetType, "__doPostBack", _
            "function __doPostBack(eventTarget, eventArgument) { " & _
            "    theForm = document.forms[0]; " & _
            "    if (!theForm.onsubmit || (theForm.onsubmit() != false)) { " & _
            "        theForm.__EVENTTARGET.value = eventTarget; " & _
            "        theForm.__EVENTARGUMENT.value = eventArgument; " & _
            "        theForm.submit(); " & _
            "    } " & _
            "} " _
            , True)

This line is the work-around: "    theForm = document.forms[0]; " & _

I include this tip in case "theForm is undefined" is searched here at Tek-tips and so perhaps may save someone a minute or two down the road.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top