HOWTO: Enable the SOM on an ASP That Has a <Form> Tag

ID: Q232218


The information in this article applies to:
  • Microsoft Visual InterDev, version 6.0


SUMMARY

This article assumes that you are familiar with HTML, Active Server Pages (ASP), and the Scripting Object Model (SOM). When you have a FORM tag on your ASP, and you enable the SOM either manually or by adding server-side Design-Time Controls (DTC) to the ASP, the FORM might no longer be functioning properly and errors might occur. This article describes the issues relating to ASPs with nested FORM tags and offers procedures to work around them.


MORE INFORMATION

Sample Scenario:

If you have an ASP with the following FORM:

<FORM id=form1 name=form1 action="action.asp">
<BODY LANGUAGE=javascript onload="return window_onload()">
<INPUT type="text" id=text1 name=text1> 
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</BODY>
</FORM>  
in the window_onload client event handler, (use the Script Outline of Visual InterDev's Interactive Development Environment (IDE) to go to the window_onload script block), you have the following code to initialize the textbox named text1:

function window_onload() { 
 Form1.text1.value =('test'); 
}  

Undesired Behavior

When you enable SOM (either manually or after dragging and dropping any DTCs to the ASP), and then view the ASP in a Web browser after enabling the SOM, the following errors or behaviors can occur:
  1. An error message indicating:
    Form1 is undefined
  2. When using the SUBMIT button to submit the ASP, the ASP is not being submitted to the action handler, in this case, "action.asp:"
This occurs because when you enable the SOM, an additional FORM tag is added to the ASP as shown below:

<FORM name=thisForm METHOD=post> 
This generally results in errors in two areas:
  • errors when referencing HTML intrinsic controls and ActiveX controls and,


  • errors when submitting the ASP.


Workaround

To work around this problem, follow the steps below:
  1. Remove the original FORM tag, in this case, the following two lines:


  2. 
    <FORM id=form1 name=form1 action="action.asp">
    ... 
    </FORM>  
  3. To ensure the controls (ActiveX, HTML intrinsic, and DTCs) on the ASP are referenced properly, change the window_onload event handler to the following, specifying 'thisForm' instead of the FORM name:


  4. 
    function window_onload() { 
     thisForm.text1.value =('test'); 
    }  
  5. The following line is added to the ASP by enabling the SOM:


  6. 
     <FORM name=thisForm METHOD=post> 
    Because the above line is not editable from within Visual InterDev, you need to specify the FORM action handler in a separate function. In this case, you can modify the original ASP to manually submit the page as shown below:
    
    <FORM name=thisForm METHOD=post>
    <BODY LANGUAGE=javascript onload="return window_onload()">
    <INPUT type="text" id=text1 name=text1>
    <INPUT type="submit" value="Submit" id=submit1 name=submit1 onclick="manualsubmit()">
    </BODY>
    </FORM> 
    The function "manualsubmit" is added to submit the form to the correct ASP, in this case, "action.asp:"
    
    <SCRIPT LANGUAGE="JAVAScript">
    function manualsubmit()
    { 
       thisForm.action='action.asp'; 
    }
    </SCRIPT>  


REFERENCES

For additional information, please click the article number below to view it in the Microsoft Knowledge Base:

Q191969 PRB: Form Does Not Work When Using DTCs with Nested Form Tags

Additional query words:

Keywords : kbVisID600 kbGrpASP
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: August 31, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.