Page 1 of 1

Form action to self and other page

Posted: Mon Sep 08, 2014 4:53 am
by Elasek
hi,

How can i make a <form> have 2 submit buttons, and make 1 to go to the same page (like action="", or phpself, whatever works.)
and the other submit button to an other page (like action="otherpage.php").

They both have to take the data from the input field ofcourse.

I found on the internet to try use functions like this:

<form action='default.php'>
<button onclick='updateform()' value='edit'/>
<button onclick='submitform()' value='delete'/>
</form>

function updateform() {
$('form').action = 'editaction.php';
$('form').submit();
}

function submitform) {
$('form').action = 'deleteaction.php';
$('form').submit();
}

but when i run it, i just get a blank page.

Hope someone can help me.

Thanks in advance.

Re: Form action to self and other page

Posted: Mon Sep 08, 2014 6:50 am
by Celauran
Which blank page are you getting? Also, as buttons submit the form by default, you'll want to preventDefault on click.

Re: Form action to self and other page

Posted: Mon Sep 08, 2014 7:09 am
by Elasek
Just a whole blank page, nothing on it. that happens here in i guess when the code is not working, had it before.

maybe it helps if i show some more.

This is what i have made so far: http://prntscr.com/4ku356
when i click on one of the buttons it refreshes this same page so it updates the title or whatever is edited.

Now i want that when i click the button on the right side i go to an other page(savereport.php) with the same data as when i click on the left one.

Re: Form action to self and other page

Posted: Mon Sep 08, 2014 7:14 am
by Celauran
I'd start by turning on error reporting so you get something more meaningful than a blank page. In your initial example, you specified three form actions; default, editaction, and deleteaction. This means there are three different scripts that could be failing, and the JS functions may or may not be failing as well.

Re: Form action to self and other page

Posted: Mon Sep 08, 2014 7:17 am
by Elasek
I just found out i can simply use: onclick="form.action='savereport.php'" to get somewhere else than the form action.

Thanks for the help tho, im certainly going to add some error pages so i can see whats going on next time.