Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Passing a form variable to action onSubmit?

6:43 am on Aug 18, 2009 (gmt 0)

New User

10+ Year Member

joined:Aug 4, 2004
posts: 26
votes: 0

Hi all,

I am having a bit of trouble trying to solve an issue.

My issue:

- I have a form with an input field.
- I need to pass the value of said input filed into the form's action. That is, I need to generate a URL based on the value of the input field.

So if the user inputs the value "hello", I need the action to be: action="page/hello".

Is this possible?

Any help with this would be much appreciated.

Cheers in advance.

7:39 am on Aug 18, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 7, 2004
votes: 0

Hi, try this:

function s(o) {
o.action = 'page/' + o.elements[1].value;

and the form looks like this

<form id="frm" method="post" action="/" onsubmit="s(this);">

HTH, Tom

6:11 pm on Aug 18, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
votes: 10

Users with JavaScript disabled might not be very happy though.