Confirm() Function in javascript

A CONFIRM box is used when you are trying to get a YES / NO answer from the visitor. The OK button acts as the YES response the CANCEL button acts as the NO response.
To get the CONFIRM actions to perform, we have to use a VARIABLE situation to control it. That means, we have to use a bit of algebra to temporarilly assign a value to the visitor's answer choice. After the value (answer) is determined, the script then carries out the set of instructions accordingly. This is usually done with an IF...ELSE statement. IF the answer is true, do this. ELSE the answer is false, so do this instead.

Examples
  • JavaScript Confirm() - example of using a JavaScript confirm() method. Returns a boolean true or false.
    Ex: <a href="javascript: confirm('When finished, click OK'); void('')">JavaScript Confirm()</a>
  • Results Example - Showing how to capture the results.  Returns a boolean true or false. 
    Ex: <a href="javascript: alert('Your choice was: ' + confirm('When finished, click OK') ); void('')">Results Example</a>
  • If Example - Showing how to capture the results.  Returns a boolean true or false. 
    Ex: <a href="javascript: if (confirm('Continue?')) { alert('You chose true') } else { alert('You chose false.') }; void('')">
  • Confirm OK, then goto URL (uses onclick()) - Confirm, then next web page - If you press 'OK', then you will launch another web page.
    Ex: <a href="ex_confirm_continuepressed.htm" onclick = "if (! confirm('Continue?')) return false;">
  • Confirm OK, then popup a new window (uses onclick()) - Confirm, then next web page - If you press 'OK', then you will launch another web page.
    Ex: <a href="ex_confirm_continuepressed.htm" onclick = "if (! confirm('Continue?')) return false;">
  • Confirm OK, then goto a URL (uses window.location.href) - Confirm, then next web page - If you press 'OK', then you will launch another web page.
    Ex: <a href="javascript: if (confirm('Continue?')) { window.location.href='ex_confirm_continuepressed.htm' } else { void('') }; ">
  • Confirm OK, then popup a new window (uses window.open()) - Confirm, then next web page - If you press 'OK', then you will launch another web page.
    Ex: <a href="javascript: if (confirm('Continue?')) { window.open('ex_confirm_continuepressed.htm'); void('') } else { void('') }; ">
  • The normal html would look like:
    blnAnswer = confirm('When finished, click OK')
Posted in: programming asp.net | Tags: javascript confirm alert href