PRB: Cannot Dynamically Set form.action in Internet Explorer 3.x |
Q164497
In the versions of Internet Explorer listed above, setting the action property of a form does not result in the new value being used when the form is submitted. Instead the original value is used.
This behavior is by design.
Either all form processing must done with the same action or additional hidden forms must be used, one for each possible action. An example of this is given below.
NOTE: Setting the form action dynamically is supported in Internet Explorer 4.0 and later.
<HTML>
<HEAD>
<TITLE>Form Action Example</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function change( ) {
document.MyFm.action="action2.asp";
alert("Form.action was changed to " + document.MyFm.action);
update_field();
}
function update_field()
{
document.MyFm.FormAction.value=document.MyFm.action
}
// -->
</SCRIPT>
</HEAD>
<BODY onload="update_field()">
<FORM NAME="MyFm" METHOD=POST ACTION="action1.asp" onSubmit="alert(MyFm.action);">
The Form.Action for this page is originally set to action1.asp.
Click the change button to change the action property to action2.asp.
<BR>
Click the submit button to see which action URL is accessed.
<BR>
Current Form Action:
<INPUT TYPE="text" name="FormAction">
<BR/><BR/>
<INPUT TYPE="Button" VALUE="Change" onClick="change();">
<INPUT TYPE="Submit">
</FORM>
</BODY>
</HTML>
Put the following two Active Server Pages (ASP) files into the same directory as the HTML page above:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>Test Action Page 1</TITLE>
</HEAD>
<BODY>
<H2>Action 1</H2></BR>
<%
Response.Write "<H3>Form [POST] items : " & Request.form.count & "</H3><BR/>"
for each rItem in Request.Form
Response.Write ( rItem & " : " & Request.form(ritem) & "<BR/>")
next
%>
</BODY>
</HTML> Action2.asp
<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>Test Action Page 2</TITLE>
</HEAD>
<BODY>
<H2>Action 2</H2><BR/>
<%
Response.Write "<H3>Form [POST] items : "_
& Request.form.count & "</H3><BR/>"
for each rItem in Request.Form
Response.Write ( rItem & " : " & Request.form(ritem) & "<BR/>")
next
%>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Form Action Example</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
myAction="MyFM1"
function change( ) {
myAction="MyFM2";
alert("Form to be used has been changed to " + myAction);
update_field();
}
function update_field()
{
document.MyFm1.FormAction.value=myAction
}
function do_submit()
{
if (myAction == "MyFM2")
document.MyFm2.FormAction.value=document.MyFm1.FormAction.value
document.forms(myAction).submit()
}
// -->
</SCRIPT>
</HEAD>
<BODY onload="update_field()">
This page illustrates using the multiform approach to solve the problem of not being able to change the form action in Internet Explorer 3.
Note that the submit is a normal HTML input button and not a true submit button.
<FORM NAME="MyFm1" METHOD=POST ACTION="action1.asp">
Current Form:
<INPUT TYPE="text" name="FormAction">
<BR/><BR/>
<INPUT TYPE="Button" VALUE="Change" onClick="change();">
<INPUT TYPE="Button" Value="Submit" onClick="do_submit();">
</FORM>
<FORM NAME="MyFm2" METHOD=POST ACTION="action2.asp">
<INPUT TYPE="hidden" name="FormAction">
</FORM>
</BODY>
</HTML>
Additional query words:
Keywords : kbprogramming kbIE300 kbIE301 kbIE302 kbGrpDSInet kbDSupport
Issue type : kbprb
Technology : kbIEsearch kbAudDeveloper kbSDKIESearch kbSDKIE300 kbSDKIE301 kbSDKIE302
|
Last Reviewed: October 31, 1999 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |