button click to submit two seperate forms

L

libsfan01

Hi all

is it possible to onclick of a button in one form submit that form and
also submit another form on the same page, both with the same 'action'
location? or is it only possible to send one at a time?

kind regards

Marc
 
M

maya

libsfan01 said:
Hi all

is it possible to onclick of a button in one form submit that form and
also submit another form on the same page, both with the same 'action'
location? or is it only possible to send one at a time?

kind regards

Marc

<button onClick="submitForms()">submit</button>

function submitForms() {
document.form1.submit();
document.form2.submit();
}

only problem I personally have with this method is this, in <form> tag

onSubmit="return submitForm(this)"

gets ignored.. you can also do 'submit' button with an image, thus:

<input type="image" src="send.jpg" border=0
onMouseOver="this.src='send_roll.jpg'" onMouseOut="this.src='send.jpg'">

this works because when you do "input type=image" it defaults to
'submit' type... (and as you can see you can also do a rollover for
it..) I have not found a way to do it like this for 'reset' button, so
for 'reset' button I do

<img src="reset.jpg" onClick="resetForms()" border=0
onMouseOver="this.src='reset_roll.jpg'" onMouseOut="this.src='reset.jpg'">

reset function:

function resetForms() {
document.form1.reset();
document.form2.reset();
}

I wonder if anybody here can tell me how to do this with a <button> so
call to validation function in <form> tag isn't ignored?
 
D

David Dorward

maya said:
<button onClick="submitForms()">submit</button>

function submitForms() {
document.form1.submit();
document.form2.submit();
}

The second form submission will cancel the first one (unless the browser
leaves the page soon enough to never reach the second one).
only problem I personally have with this method is this, in <form> tag

onSubmit="return submitForm(this)"

gets ignored..

Yes. The onsubmit event fires when the user submits the form - not when a
script submits the form.
<input type="image" src="send.jpg" border=0
onMouseOver="this.src='send_roll.jpg'" onMouseOut="this.src='send.jpg'">

this works because when you do "input type=image" it defaults to
'submit' type...

No. Image inputs submit forms, but they aren't "the submit type"
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top