scriptygoddess

05 Jun, 2003

Javascript – two submit buttons – two seperate purposes

Posted by: Jennifer In: Bookmarks

Needed this for a script I'm working on where one button will be doing one thing, another will be deleting stuff. So I needed a button that had a "confirm" message before going ahead and deleting stuff – but both buttons needed to submit the form (I would check the VALUE of the submit button via php). This script shows how to tie a confirm message to one button.

7 Responses to "Javascript – two submit buttons – two seperate purposes"

1 | Happy

June 6th, 2003 at 12:58 pm

Avatar

It probably would've been cleaner to just put the confirm() function in the onClick attribute instead of calling a user-defined function, saving the response to a variable, testing the variable, and then returning true or false.

confirm() returns a true or false anyway, so the whole thing could be reduced to:

<input type="submit" value="Delete" onClick="return confirm('Are you sure?')" >

2 | Jennifer

June 9th, 2003 at 8:23 am

Avatar

I guess the only benefit to it being OUTSIDE of the tag itself, is in the case you have a really long confirm message. "You are about to destroy your entire blog. There is no turning back. Are you really absolutely positvely sure you want to delete your entire blog, all your hard work over so many years?" 😉

Or maybe if there's more than one form that has the same confirm message? or if you want to include other validation stuff…?

There's probably other scenarios I can think of where this would be usefull… but it's good to know if it only needs a simple solution – one is available. :)

3 | insin

June 10th, 2003 at 6:08 am

Avatar

Another way to have more than one submit button – use a button's onclick to call a JavaScript function to change the form's action then submit it.

eg. I have a form which can be used to update or delete an item. The hard-coded form action will update the item when you click on the submit button (labeled "Update"), while I have the "Delete" button call this function:

function doDelete()
{
if(confirm("Do you want to delete this Pre-Requisite Software Item?"))
{
document.preReqForm.action = "DeletePreReqItem.do?section=PreReqSoft&tab=tab3";
document.preReqForm.submit();
}
}

4 | JUan

July 25th, 2003 at 4:55 pm

Avatar

Your tutorial are good, easy to understand!
Thank You, very much.

5 | Anonymous

September 13th, 2003 at 9:03 pm

Avatar

Huh, I don't see the correlation?

Re:

"Google Reference

I noticed you arrived here via Google looking for seperate.
To aid you on your search, here are the top results for your keywords:

August 12, 2003 – "Hi" Script
June 26, 2003 – Javascript: Exploding a string into an array
June 20, 2003 – Comment Queue Script/MT hack UPDATED
June 10, 2003 – Coment Queue Script/MT Hack "

6 | Jennifer

September 13th, 2003 at 9:09 pm

Avatar

That is a script completely unrelated to this post that tries to help people coming from Google by searching the rest of the site for similar keywords. Your keyword was "Seperate" – seperate is in the title of this post – as it is probably also in those other posts. It's more for when people are searching for specfic scripts, and they happen to come to a page that may not be the best fit.

7 | Levent Demir

April 8th, 2004 at 6:17 am

Avatar

that is what i want

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements