Avatar of Lia Nungaray
Lia Nungaray
Flag for United States of America asked on

Create a message box with three buttons

I have a button at the end of a form which runs an update query and I added a message that pops up asking the user to confirm if the record is to be updated. I now would like to give the user another choice, how can I add an extra button to accomplish this? Here's the code I have so far:

function doSaveRpt(button, command)
{
  var message = "Are you sure you want to save this report?";
  var proceed = confirm(message);
  if(proceed)
  {
      button.form.command.value = command;
      button.form.submit();
  }
}

With this code, I only get two buttons, OK and Cancel. I would like to change the display of the buttons, for example, Save and Complete, Save and Pending, Cancel. Thanks!
JavaScript

Avatar of undefined
Last Comment
Zvonko

8/22/2022 - Mon
geordie007


the confirm box is part of the browser code, you can't change it. javascript only allows for three different boxes (alert, confirm and query). you'll have to do it another way, perhaps by having the buttons within the page rather than on the javascript box.
Zvonko

There is no way to make three buttons alerts beside messing with VBScript, and there you cannot label the default buttons.
But why not extend your function like this:


function doSaveRpt(button, command){
  if(confirm("Are you sure you want to COMPLETE this report?")){
     button.form.command.value = "COMPLETE " + command;
     button.form.submit();
  } else {
    if(confirm("Do you want to SAVE this report?")){
       button.form.command.value = "SAVE " +command;
       button.form.submit();
    } else {
      return false;
    }
  }
}

light_bulb

Take a look at this:

http://slayeroffice.com/code/custom_alert/

It makes custom alert boxes; I don't see why you can't do the same with a prompt and add more buttons.  Looks like a lot of code, though.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Lia Nungaray

ASKER
I like your suggestion Zvonko, but I might need to change this code a little, I'm not very familiar with JavaScript, so I'll need your help.... Here's the pseudocode:

function doSaveRpt(button, command)
message = "Are you sure you want to save this record?"
if user response is yes
{
     var message = "Are you done filling in all your department sections of the report?"
     if user response is yes
     {
        assign saveC to command (This to run the query to update and change status to complete)
     else if user response is no
       assign saveP to command (This to run the query to update and keep current pending status)
    end if
    }
elseif user response is no
   do nothing
end if
}

Something along these lines... Thanks!

ASKER CERTIFIED SOLUTION
Zvonko

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Lia Nungaray

ASKER
Excellent. Thanks!
Zvonko

You are welcome.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.