Board index » delphi » Dynamically change form's action

Dynamically change form's action


2005-02-05 03:13:10 AM
delphi163
Hi all,
This is more of a java script question than a web broker question but I'm
hoping someone has run across similar before.
I would like to set the action of a form on the fly and then submit... seems
reasonable enough.. I have the function
funtion MySubmit( sAction, AForm )
{
AForm.action = sAction;
....
AForm.submit();
}
the function is called on the page like MySubmit(
'myweb.com/my_isapi.dll/hello', MyFormName )
MyFormName is defined as:
<form name="MyFormName" method="POST">
<input type="hidden" name="myaction" value="">
</form>
It doesn't seem to set the action variable... not sure why.. no errors..
Any ideas,
Thanks
 
 

Re:Dynamically change form's action

Vernon writes:
Vernon,
Quote
MyFormName is defined as:

<form name="MyFormName" method="POST">
<input type="hidden" name="myaction" value="">
</form>
You don't have the action defined in your form.
< form name = "myFormName" action=" "...
method="post"...
</form>
There could be other problems too but we can not tell unless we see how your
MySubmit function is being called.
Rich Bakos
Rich Bakos
 

Re:Dynamically change form's action

Rich,
Thanks for the response. I tried it both ways with the action in the form
declaration and without. The function is called from an onclick event, ie.
..
<TD onmouseover="navigateOver(this, 'dropdown', 'blue', '#A2C2FC');"
onclick=" MySubmit('www.mysite.com', myFormName ); "
onmouseout="navigateOut(this, 'dropdown');">My Lists/Data Filters</TD>
I've circumvented the problem by defining multiple hidden form objects and
passing the needed one... but I am curious to find out why the dynamic
assignment does not seem to take. All other variables seem to assign fine
except the action property.
I've search the news groups and all I could find on it is that dynamic
assignment was not supported in IE 3..
It might be helpful to note that I am testing on IE 6.0...
thanks,
Vernon.
"Rich Bakos" <XXXX@XXXXX.COM>writes
Quote
Vernon writes:

Vernon,

>MyFormName is defined as:
>
><form name="MyFormName" method="POST">
><input type="hidden" name="myaction" value="">
></form>

You don't have the action defined in your form.

< form name = "myFormName" action=" "...
method="post"...
</form>

There could be other problems too but we can not tell unless we see how your
MySubmit function is being called.

Rich Bakos

Rich Bakos



 

Re:Dynamically change form's action

Might not be the problem but .... myFormName and MyFormName (caps M) might
be unresolvable for javascript. Its really case sensative to the point that
its a {*word*75}.
 

Re:Dynamically change form's action

Vernon writes:
Vernon,
Quote
<TD onmouseover="navigateOver(this, 'dropdown', 'blue', '#A2C2FC');"
onclick=" MySubmit('www.mysite.com', myFormName ); "
onmouseout="navigateOut(this, 'dropdown');">My Lists/Data
Filters</TD>
Give this a try - Notice the form name is passed as a string.:
<TD onmouseover="navigateOver(this, 'dropdown', 'blue', '#A2C2FC');"
onclick=" MySubmit('www.mysite.com', 'myFormName' ); "
onmouseout="navigateOut(this, 'dropdown');">My Lists/Data
Filters</TD>
funtion MySubmit( sAction, AForm )
{
var frm = document.forms[AForm];
frm.action = sAction;
....
frm.submit();
}
Untested, I am no Javascript pro.
Rich Bakos
 

Re:Dynamically change form's action

Do you remember the days of debugging with "writeln" statements? Well,
that's pretty much all you can do with Javascript. Put an Alert statement
before and after you set the form action.
funtion MySubmit( sAction, AForm )
{
alert('Action = ' + sAction);
alert('Before = ' + AForm.action);
AForm.action = sAction;
alert('After = ' + AForm.action);
....
AForm.submit();
}
What your doing is pretty standard stuff. My bet is a syntax error
somewhere.
DaveH
"Vernon" <XXXX@XXXXX.COM>writes
Quote
Rich,

Thanks for the response. I tried it both ways with the action in the form
declaration and without. The function is called from an onclick event, ie.
..

<TD onmouseover="navigateOver(this, 'dropdown', 'blue', '#A2C2FC');"
onclick=" MySubmit('www.mysite.com', myFormName ); "
onmouseout="navigateOut(this, 'dropdown');">My Lists/Data Filters</TD>

I've circumvented the problem by defining multiple hidden form objects and
passing the needed one... but I am curious to find out why the dynamic
assignment does not seem to take. All other variables seem to assign fine
except the action property.

I've search the news groups and all I could find on it is that dynamic
assignment was not supported in IE 3..

It might be helpful to note that I am testing on IE 6.0...

thanks,

Vernon.


"Rich Bakos" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Vernon writes:
>
>Vernon,
>
>>MyFormName is defined as:
>>
>><form name="MyFormName" method="POST">
>><input type="hidden" name="myaction" value="">
>></form>
>
>You don't have the action defined in your form.
>
>< form name = "myFormName" action=" "...
>method="post"...
></form>
>
>There could be other problems too but we can not tell unless we see how
>your
>MySubmit function is being called.
>
>Rich Bakos
>
>Rich Bakos
>
>
>


 

Re:Dynamically change form's action

To get the form object you can use
var MyForm = document.getElementById('MyFormId');
In your html source, declare your form with an id like this:
<form id="MyFormId" method="post">
then you can do
var MyForm = document.getElementById('MyFormId');
MyForm.action = 'http.... etc';
MyForm.submit();
-Bill Egge
isapi tools
www.eggcentric.com/
 

Re:Dynamically change form's action

Thanks Guys for the suggestions.
I walked away from it yesterday and came back this morning and realized that
Dave was right. I was calling
MyFormName.action.value = sAction... and not MyFormName.action = sAction...
silly me.. most have looked at that line 100 times...
Goes to show.. sometimes... you just got to step away.. and clean the (red)
eyes..
Thanks again..
Vernon.
"Dave Hackett" <XXXX@XXXXX.COM>writes
Quote
Do you remember the days of debugging with "writeln" statements? Well,
that's pretty much all you can do with Javascript. Put an Alert statement
before and after you set the form action.

funtion MySubmit( sAction, AForm )
{
alert('Action = ' + sAction);
alert('Before = ' + AForm.action);
AForm.action = sAction;
alert('After = ' + AForm.action);
....
AForm.submit();
}