• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

Multiple actions per HTML form?

Question

jackwanders    0

Is it possible to make an HTML form that has a different action, depending on the button clicked? I have a form w/ two buttons, and each button will do extremely different things. The way I have it layed out on the page really doesn't allow for me to break it up into two forms, though.

So...any way to do this?

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0
[pioneer]    0

If you want to achieve that, then another programming/scripting language must be learnt.

I use php and I like it, I think it?s easy to use too.

Share this post


Link to post
Share on other sites
  • 0
Bloozie    1

ASP.NET :D

Faster than PHP + Easier syntax that PHP = Better than PHP

Only works on WinBoxes though :(

Share this post


Link to post
Share on other sites
  • 0
draelas    0

ya with php you could have the action run a script that said

if this button is clicked do this

or if this other one is clicked do this other thing

Share this post


Link to post
Share on other sites
  • 0
Dragon75    0

No you can do with with just a little Client side JavaSript.

First make your first form and button.

Then make a second form with all of the inputs hidden. and put the second button in the form.

If the first form is clicked go as normal.

If the second button is click go to a JS function and copy the data from form one to from two. THis way all the data is now in for two then submit.

It will look something like this

<html>

<head>

<title>Untitled</title>

<script language="JavaScript">

function Copydata(){

document.form2.input1.value = document.form1.input1.value;

document.form2.submit();

}

</script>

</head>

<body>

<FORM METHOD="POST" id=form1 name=form1 action="">

<input type="text" name="input1">

<input type="submit" name="Submit1">

</FORM>

<FORM METHOD="POST" id=form2 name=form2 action="">

<input type="hidden" name="input1">

<input type="button" name="Submit2" value="Submit" onclick="Copydata()">

</FORM>

</body>

</html>

All you need is html and client side Javascript and you are done. Nothing more is need :)

Edited by Dragon75

Share this post


Link to post
Share on other sites
  • 0
jackwanders    0

Good work, Dragon. Couldn't I do it this way, though:

<html>

<head>

<title>Untitled</title>

<script language="JavaScript">

function Copydata(){

document.form2.input1.value = document.form1.input1.value;

}

</script>

</head>

<body>

<FORM METHOD="POST" id=form1 name=form1 action="firstaction.php">

<input type="text" name="input1">

<input type="submit" name="Submit1">

</FORM>

<FORM METHOD="POST" id=form2 name=form2 action="secondaction.php">

<input type="hidden" name="input1">

<input type="button" name="Submit2" value="Submit" onclick="Copydata()">

</FORM>

</body>

</html>

Share this post


Link to post
Share on other sites
  • 0
Dragon75    0

Thanks I have done this a few times before.

:)

You need a way to submit the second form. If you look closly it is a button and not a submit so you will need the submit as the end of your function.

Share this post


Link to post
Share on other sites
  • 0
JaytheletterJ    0
Only works on WinBoxes though

so what's wrong with that? ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.