Forum Moderators: open

Message Too Old, No Replies

Putting a form's "action" somewhere other than the form tag.

Looking for some help with the form.submit() function

         

seona

5:39 am on Jul 6, 2004 (gmt 0)

10+ Year Member



Hi guys,

Not sure if this is the right forum for this question, but I couldn't work out if there was a better one.

I have a page with a form in it. Using a JavaScript free method for making two related select boxes (i.e. where selecting something in one select box changes the contents of the second one) requires me to not have the "action" attribute of the form tag defined. The problem with this is that when I then go to submit the form, it doesn't know where to go.

So I've been trying to find information on the form.submit() function - the key word here is "trying". So maybe someone can tell me: is it possible to pass as an argument to this function a location for the form to submit to? I've tried a couple of ways of doing it, and it's not working for me.

Alternatively, if there is a better way of doing this I would love to hear it.

Cheers,

Seona.

Hester

9:07 am on Jul 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I sometimes do this:

<form method="post" name="theForm" onSubmit="return newJump()" action="" etc... >
<select name="jump">

This works with drop-down menus - not sure about other forms. The JavaScript then passes the user to the correct page:

function newJump()
{if (document.theForm.jump)
{target = document.theForm.jump.options[document.theForm.jump.selectedIndex].value;
if (target!= "nought")
{top.location = target;
window.target;}
window.self.location=target;
return false;}
return true;}

kaled

9:36 am on Jul 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem,

You can assign the form's action in javascript. So, with a little effort, you can choose different actions depending contents.

You need to assign the following:-


<FORM ONSUBMIT="return submitform(this);">

function submitform(form)
{ with (form) {
......

action = '/cgi-bin/.......';
return 1; { return zero to stop form submission }
}}

Kaled.

dcrombie

10:15 am on Jul 6, 2004 (gmt 0)



I can't think of any reason why you couldn't have a normal form action AND javascript. Are you sure that's a limitation of the script?

<FORM action="handler.cgi" onSubmit="return checkForm(this);"> 
...
</FORM>