473,378 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Two actions on a form

Hello,

I can't do two actions wich must be done on a form having two buttons.
(payment by invoice and payment by Credit card)

The first action establishes a link on two differents pages according
to whether one wants to pay by invoice or credit card. (2 buttons send)
The second action is for check if all the fields were filled.
The two codes are ok by themselves but do not work together!

For the first action (links) I have:

<script language='Javascript'>
function setAction(name) {
if (name=="submit1")
document.forms[0].action= "invoice.php"
else if (name=="submit2")
document.forms[0].action= "credit_card.php"
}
</script>

and on the form:
<input type="submit" id="submit1" name="submit1"
onClick="setAction(this.name)"
<input type="submit" id="submit2" name="submit2"
onClick="setAction(this.name)"
....

and for the second action (check fields) :

<script type="text/javascript">
function verif_fields()
{
if(document.form1.name.value == "")
{
alert("Write your name");
document.forml.name.focus();
return false;
}
if(document.form.email.value == "")
{
alert("Write your email.......
....
return confirm("ok");
}
</script>

and in the form:
<form name="form1" method="post" onSubmit="return verif_fields()" >

I try to do like this but it doesn't work! :

<script type="text/javascript">
function verif_fields()
{
if(document.forml.name.value == "")
{
alert("Write your name");
document.forml.name.focus();
return false;
}
if(document.forml.email.value == "")
{
alert("Write your email ...
....
document.form1.action = button==1? "invoice.php" : "credit_card.php";
return confirm("Ok");
}
</script>

and in the form :

<form name="forml" method="post" onSubmit="return verif_fields()">

<input type="submit" id="submit1" name="submit1" onClick="button=1"
value="Invoice">
<input type="submit" id="submit2" name="submit2" onClick="button=2"
value="Credit card">

Is somebody can help me? Thanks, pascal

Nov 9 '06 #1
1 1534
elia wrote:
I can't do two actions wich must be done on a form having two buttons.
(payment by invoice and payment by Credit card)
No, it mustn't. Give the buttons a control name (typically the same) and
the one used to submit the form will be successful. That is, its control
name and value will be added to the data set sent to the server. You can
then determine the necessary processing server-side.

It may not be a good idea to have two submit buttons in this case.
Instead, consider using radio buttons or a select element to allow the
user to choose between methods.

Relying on scripting is not a good idea at the best of times. Doing it
with e-commerce solutions is utterly stupid: the idea is to get money
from people, and one cannot do that if the site doesn't work.

[snip]

Mike
Nov 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kay Schluehr | last post by:
Hi all, thanks for Your attention ! I think my proposal was more in mind of Rons modified exec than Pythons lambda. When George proposed his unpacking behavoir for list-comps as a pack of...
1
by: Sophisticado | last post by:
Hi Newbie here. I am trying to have two form actions on submission using a javascript. The first calls a php class (http://www.blah.org/test.php) and the second adds data to a mySQL database...
1
by: ammarton | last post by:
Hello all...I'm a bit new to working with Macros in Access so forgive me if the terminology I use is not accurate. To preface this, basically I am using a form on a replicated database so the...
1
by: Perra | last post by:
If I create a form, set Opacity to some thing like 50%, set TopMost = True, set CausesValidation = False, I will get a transparen form that is transparent for keyboard action. (You can work with...
1
by: genojoe | last post by:
In Microsoft Access, I use Application.Echo False ......code that causes form to flash Application.Echo True to hide intermediate actions while a form is visible. I cannot find an...
9
by: Mark | last post by:
I have a lengthy form (i.e., many inputs) on my form.php page. What's different about this form than many others I've created is that I want the user to have a choice of submitting this form data...
8
by: yawnmoth | last post by:
Say I have the following HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> <form action="">
5
by: Tyrone Slothrop | last post by:
I have created a form which has two submit buttons. The first is a preview button to view the data they have entered into a formated page. The second actually submits the data for saving. The...
6
by: Sarvananda | last post by:
I have two forms: 1. Donor 2. Patron I want to bring the two forms together in a tab control on separate pages. I had some startup actions to be triggered for each form. Which event in the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.