Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
HTML Pages with CSS and JavaScript
Which submit button was clicked?
Jamie Cotton
Greenhorn
Posts: 16
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have a form with 2 submit buttons
I have the following:
<form action="page.php" method="post" onsubmit="return errorsOnSubmit(this);">
My question is how can I in my errorsOnSubmit() function check which submit button was clicked??
Cheers
Eric Pascarello
author
Posts: 15385
6
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Well with Firefox you would be able to do something like this:
<script type="text/javascript"> function test(e,f){ alert(e.explicitOriginalTarget.name); return false; } </script> <form name="asdf" action="#" onsubmit="return test(event, this)" > <input type="submit" name="s1" /> <input type="submit" name="s2" /> </form>
Problem is IE's window.event does not give us this info.
So if you want to get wat button was clicked with JavaScript, you will have to add an onclick handler to your buttons.
Eric
Jamie Cotton
Greenhorn
Posts: 16
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi could you please explain the on click handler
I have tried
onclick="goBack=false"
onclick="goBack=true"
but IE does not pick this up but Firefox does
Jamie Cotton
Greenhorn
Posts: 16
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This works in firefox but not IE why?
<html> <head> <script type="text/javascript"> function errorsOnSubmit(whichCase) { if(whichCase=="button2") { alert("next was pressed") } } </script> </head> <body> <form onsubmit="return errorsOnSubmit(whichPressed)"> <button name="whichSubmit" type="submit" value="button1" onclick="whichPressed=this.value">Back</button> <button name="whichSubmit" type="submit" value="button2" onclick="whichPressed=this.value">Next</button> </form> </body> </html>
Dawn Charangat
Ranch Hand
Posts: 249
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Change your program to the one below, it will work.
<html> <head> <script type="text/javascript"> var whichPressed; function errorsOnSubmit() { if(whichPressed=="Next") { alert("next was pressed") } } </script> </head> <body> <form onsubmit="errorsOnSubmit()"> <input name="whichSubmit" type="submit" value="Back" onclick="whichPressed=this.value" /> <input name="whichSubmit" type="submit" value="Next" onclick="whichPressed=this.value" /> </form> </body> </html>
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JSP page with four buttons
Form - 2 different Action Attributes on Submit?
Disabling form submission in IE and Firefox
Check which button was clicked Form Plugin
multiple submit buttons
More...