One Form, Two Targets, Two Actions

T

Tyrone Slothrop

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 two
submit buttons have onclick events defined for both the targets and
actions. These are both working OK.

However, I have an onsubmit event in the form tag which validates the
data which is also triggered when the preview button is clicked. I
want to block this behavior.

Is there a way to determine which button is clicked in the validation
function, or bypass it altogether? Perhaps there is a better way to
trigger the validation than onsubmit?

TIA!
 
L

Lee

Tyrone Slothrop said:
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 two
submit buttons have onclick events defined for both the targets and
actions. These are both working OK.

However, I have an onsubmit event in the form tag which validates the
data which is also triggered when the preview button is clicked. I
want to block this behavior.

Is there a way to determine which button is clicked in the validation
function, or bypass it altogether? Perhaps there is a better way to
trigger the validation than onsubmit?

I would do the preview processing locally, and do away with the
bogus submit button completely. That also allows you to avoid
the onclick handler in the "real" submit button, and so probably
even allows people with scripting disabled to use your form.


--
 
A

ASM

Tyrone Slothrop a écrit :
Is there a way to determine which button is clicked in the validation
function, or bypass it altogether? Perhaps there is a better way to
trigger the validation than onsubmit?

on my idea everything has to happen in form's onsubmit

<form onsbmit="if(but==1) return dothat(); else return dothis();" ... >
<input type=submit onclick="but=1" ... >
<input type=submit onclick="but=2" ... >
 
T

Tyrone Slothrop

Tyrone Slothrop a écrit :

on my idea everything has to happen in form's onsubmit

<form onsbmit="if(but==1) return dothat(); else return dothis();" ... >
<input type=submit onclick="but=1" ... >
<input type=submit onclick="but=2" ... >

Merci.

In short:
<form onsubmit="if(button){validateForm();}">
<input type="submit" onclick="button=true;">
 
A

ASM

Tyrone Slothrop a écrit :
Merci.

In short:
<form onsubmit="if(button){validateForm();}">
<input type="submit" onclick="button=true;">

all depends if you have one or more actions on submitting
 
J

Jonas Raoni

Tyrone Slothrop escreveu:
In short:
<form onsubmit="if(button){validateForm();}">
<input type="submit" onclick="button=true;">

The bellow code works just on Firefox :(

<input type="submit" name="save" />

if(event.originalTarget.name == "save")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top