Link to home
Avatar of Lia Nungaray
Lia NungarayFlag 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!
Avatar of geordie007
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.
Avatar of 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;
    }
  }
}

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.
Avatar of 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
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Excellent. Thanks!
You are welcome.