Javascript How to use the onSubmit Confirm Dialog with two submit buttons on JSP

There are currently two submit buttons on my form. One for Search, and the other for function Mark Complete. I need to show the confirmation dialog box ONLY when the “Finish checkmark” button is pressed in order to submit the form and submit this check. Can this be identified? I currently have a function confirmComplete:

function confirmComplete() {
alert("confirmComplete");
var answer=confirm("Are you sure you want to continue");
if (answer==true)
  {
    return true;
  }
else
  {
    return false;
  }
}

Any help would be appreciated!

+5
source share
6 answers

Set the attribute attribute of the onclick"Complete Mark " button to

 onclick="return confirm('Are you sure you want to continue')" 

and remove the confirmComplete function from the form

+24
source

.

<input type="submit" value="Search" />
<input type="submit" value="Mark Complete" onclick="{return confirmComplete();}" />

confirmComplete , ​​ .

+2

, . , , .

+1

, :

<form id="frm" action="page.php" method="post" onsubmit="return onSubmit();">
    <input />
    <input type="submit" value="sub1" onclick="sub1();" />
    <input type="submit" value="sub2" onclick="sub1();" />
</form>
 <script type="text/javascript">
<!--
var frm = document.getElementById('frm');
function onSubmit(){
    return false;
}

function sub1(){
    alert('s1');
    frm.submit();
}

function sub2(){
    alert('s2');

}
 //-->
 </script>
+1

"confirm()" javascript popup, onclick = "return confirm (" ? ")", " ?" "ok" "cancel". ok, true -, , false -.

0

, click . .

( )

:

<FORM name="F_DESTINATION_DB" id="F_DESTINATION_DB" method="POST" onsubmit="return popConfirmationBox('<?php echo LanguageControler::getGeneralTranslation("DELETE_CONFIRMATION_MESSAGE", "Deleting is an irreversible action. Are you sure that you want to proceed to the deleting?");?> ','DELETE_DB_BUTTON')">

Javascript (in an external file for code reuse):

/**
* Display a confirmation message box to validate if we must post the page or not.
*
* @param message String to display
* @param tagId String id of the tag that must display the message.
*
* @return Boolean (confirmation)
*/  
function popConfirmationBox(message, tagId){

    var confirmation = true;

    if (typeof tagId === 'string' && document.activeElement.id.toUpperCase() === tagId.toUpperCase()) {

        if (typeof message === 'string' && message.length > 0) {

            confirmation = window.confirm(message);
        }
    }

    return confirmation;
}

It was quite difficult for me to do this (I need a lot of research and testing), but the resulting code is pretty simple.

By default, I assume that the confirmation is yes (in case the button pressed is not intended to display the message or if the user did not provide the correct message line).

Additional note . Of course, this code will not do the trick if the user browser blocks the client code.

I hope this helps someone

Jonathan Roland-Levenk from Montreal

0
source

All Articles