Forum Moderators: open

Message Too Old, No Replies

Change form action - help

         

2004mark

9:41 am on Jun 28, 2005 (gmt 0)

10+ Year Member



Hello, I hope that someone can help, as I'm pulling my hair out in frustration here!

What I am trying to do is to have a from that submits to a different perl script depending on the first part of the users post code.

The idea is simple, run a small javascript that updates the action of the form, but whatever I try it will not work!

I know that it should work, because if I change the last line in the javascript to

document.contactform.testTxt.value= reqAction;

it puts the required text in to a text area (testTxt).

Here is the code that I'm using.

JAVASCRIPT

function emailLocation()
{
formElement = document.contactform.pCode[document.form1.pCode.selectedIndex];
reqAction = formElement.value + "Mail.pl"

document.contactform.action = reqAction;

}

HTML

<form action="" method="post" name="contactform">...

<select name="pCode" onchange="emailLocation()"><option value="gary">LE</option><option value="boyd">YO</option><option value="ian">G</option><option value="jason">SL</option></select>

...</form>

Why wont it work...

...please help!

kaled

2:05 pm on Jun 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suggest you try testing with Opera or Firefox and open the javascript console to check for errors.

It is certainly possible to do change the action with javascript - I do this on on my main contact page.

Kaled.