FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

form help

 


clydejaw
Hey there,

I wanna add two buttons but I'm not sure about the attributes.

There is only one action in the <form> and I was wondering if its possible to add another action for another button..

e.g. | Confirm Order | Add To Cart |
thanks.
RiCtee
Couldn't you just make 2 separate buttons. Don't understand what the problem is can you explain more.
Azmo
Code:
<input type="submit" name="send" value="Send">
<input type="reset" name="reset" value="Clear">


that's a very comon combination for a form.. or do you want the whole script in php for redirecting depending on what u click on?
MrBlueSky
clydejaw wrote:
Hey there,

I wanna add two buttons but I'm not sure about the attributes.

There is only one action in the <form> and I was wondering if its possible to add another action for another button..

e.g. | Confirm Order | Add To Cart |
thanks.


Yes. You can do it using Javascript. Give the buttons an "onclick"-attribute:

Example:

Code:

<script type="text/javascript">
function confirm() {
  // Confirm
}

function add() {
  // Add something
}
</script>

<form action>
<input type="button" value="Confirm" onclick="confirm()" />
<input type="button" value="Add" onclick="add()" />
</form>

clydejaw
yeah, not including the reset action.

It's just 2 actions.

Quote:
<script type="text/javascript">
function confirm() {
// Confirm
}

function add() {
// Add something
}
</script>

<form action>
<input type="button" value="Confirm" onclick="confirm()" />
<input type="button" value="Add" onclick="add()" />
</form>



mmm I might give this a go. So in the confirm and add method, i'd put the action in it?
sonam
If you use for action some php script then you can use as many buttons you want in same form. Just give different name for each button and with if function in action.php do different stuff.

form:
Code:
<form action="action.php">
<input type="submit" name="Confirm" value="Confirm" />
<input type="submit"  name="Add" value="Add" />
</form>



action.php:
Code:
<?php
if(@$_POST['Confirm'] == "Confirm") {
//... some stuff

   header("Location:index.php"); // redirect where you want
   exit;
}

if(@$_POST['Add'] == "Add") {
//... some stuff

   header("Location:index.php"); // redirect where you want
   exit;
}

?>


Sonam
MrBlueSky
clydejaw wrote:


mmm I might give this a go. So in the confirm and add method, i'd put the action in it?


Yes. But if your more familiar with PHP than JavaScript then sonam's solution is propably better.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.