PRB: Cannot Dynamically Set form.action in Internet Explorer 3.x
ID: Q164497
|
The information in this article applies to:
-
Microsoft Internet Explorer (Programming) versions 3.0, 3.01, 3.02
SYMPTOMS
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.
CAUSE
This behavior is by design.
RESOLUTION
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.
MORE INFORMATION
Steps to Reproduce Behavior
The following page contains a form with the action set to Action1.asp. When the Change button is clicked, a JScript function is called that is intended to change the action of the form to Action2.asp.
In the Internet Explorer versions listed above, the form is submitted to Action1.asp regardless of whether the change button was clicked.
<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:
Action1.asp
<%@ 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>
Workaround
The following sample illustrates the idea of using additional hidden forms to change the action of the form:
<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 : kbprg kbIE300 kbIE301 kbIE302 kbGrpInet kbDSupport vbObjMdlIE
Version : WINDOWS:3.0,3.01,3.02
Platform : WINDOWS
Issue type : kbprb