Can you perform 2 functions when a user presses [submit] on a form?

M

Moose

I have a form, that when a user presses the [submit] button.........2
things need to happen:
1) validate the form with a java script
2) popup a thankyou window with a java script

currently i have both functions working.......but can olny execute 1
function at a time


code:
onsubmit="openindex() "
onsubmit="ValidateForm()"


what is the syntax to run both????

thanks,
moose
 
S

SpaceGirl

Moose said:
I have a form, that when a user presses the [submit] button.........2
things need to happen:
1) validate the form with a java script
2) popup a thankyou window with a java script

currently i have both functions working.......but can olny execute 1
function at a time


code:
onsubmit="openindex() "
onsubmit="ValidateForm()"


what is the syntax to run both????

thanks,
moose

onsubmit="dosomething();dosomethingelse();onemorething();"


--


x theSpaceGirl (miranda)

# lead designer @ http://www.dhnewmedia.com #
# remove NO SPAM to email, or use form on website #
 
S

SpaceGirl

Andrew said:
*Moose* wrote:
[snip]
currently i have both functions working.......but can olny execute 1
function at a time
[snip]

what is the syntax to run both????


To invoke more than function:
onsubmit="ValidateForm(); openindex();"


why not write a wrapper function... it's cleaner than trying to stick
lots of functions actually in the onsubmit event...

<script ... >
function doStuff() {

myfunction1();
myfunction2();
myfunction3();
myfunction4();

}

</script>

onsubmit="doStuff();"
Or you could try the long way and add multiple event handlers, but there
are more caveats that way.

ahymmm yes
Personally I'd abandon anything to do with pop-ups and have the
submission page display the confirmation - for all the usual
'Googleable' reasons. However, in addition to those reasons you don't
necessarily know if the form submission will succeed, especially if the
user didn't have javascript enabled in their environment and/or the form
validation didn't function. If the user has to return to the form and
complete it again you don't want to hassle them with multiple
'Thank-you' pop-ups.


--


x theSpaceGirl (miranda)

# lead designer @ http://www.dhnewmedia.com #
# remove NO SPAM to email, or use form on website #
 
A

Andrew Urquhart

*Moose* wrote:
[snip]
currently i have both functions working.......but can olny execute 1
function at a time [snip]
what is the syntax to run both????

To invoke more than function:
onsubmit="ValidateForm(); openindex();"

Or you could try the long way and add multiple event handlers, but there
are more caveats that way.

Personally I'd abandon anything to do with pop-ups and have the
submission page display the confirmation - for all the usual
'Googleable' reasons. However, in addition to those reasons you don't
necessarily know if the form submission will succeed, especially if the
user didn't have javascript enabled in their environment and/or the form
validation didn't function. If the user has to return to the form and
complete it again you don't want to hassle them with multiple
'Thank-you' pop-ups.
--
Andrew Urquhart
- FAQ: http://www.html-faq.com
- Archive: http://www.google.com/groups?q=alt.html
- Contact me: http://andrewu.co.uk/contact/
- This post is probably time-stamped +1 hour - blame my ISP (NTL)
 
A

Andrew Urquhart

*SpaceGirl* said:
*Andrew Urquhart* said:
To invoke more than [one] function:
onsubmit="ValidateForm(); openindex();"

why not write a wrapper function... it's cleaner than trying to stick
lots of functions actually in the onsubmit event...

Yes, forgot to mention that, thanks.

[snip]
ahymmm yes

ahymmm?
--
Andrew Urquhart
- FAQ: http://www.html-faq.com
- Archive: http://www.google.com/groups?q=alt.html
- Contact me: http://andrewu.co.uk/contact/
- This post is probably time-stamped +1 hour - blame my ISP (NTL)
 
J

Jeff Thies

Andrew said:
*SpaceGirl* said:
*Andrew Urquhart* said:
To invoke more than [one] function:
onsubmit="ValidateForm(); openindex();"

why not write a wrapper function... it's cleaner than trying to stick
lots of functions actually in the onsubmit event...


Yes, forgot to mention that, thanks.

[snip]

That and you are usually returning a true/false and it may be easier to
implement

<form onsubmit="return wrapperFunc()">

function wrapperFunc(){
someFunction();

return checkForm();

}

maybe not...

Jeff
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top