When you compare a return value to true you shouldn't use return true, just true:

function RemoveProduct() {
  if (confirm("Poista?") == true) {
    return true;
  } else {
    return false;
  }
}

You don't even need to do the comparison, as the result from confirm is a boolean value:

function RemoveProduct() {
  if (confirm("Poista?")) {
    return true;
  } else {
    return false;
  }
}

And you don't even need the if statement, you can just return the result from confirm:

function RemoveProduct() {
  return confirm("Poista?");
}

Remember to use return when you use the function in an event. Example:

<input type="submit" onclick="return RemoveProduct();" />
Answer from Guffa on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ met_win_confirm.asp
Window confirm() Method
The confirm() method returns true if the user clicked "OK", otherwise false.
People also ask

What is the difference between alert() and confirm() in JavaScript?
`alert()` provides a way for the user to acknowledge any information. It displays a simple dialog box with the message and an "OK" button. `confirm()` is useful when you need the user to make a binary decision. It is used to display a dialog box with a message, along with "OK" and "Cancel" buttons.
๐ŸŒ
scaler.com
scaler.com โ€บ home โ€บ topics โ€บ javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
Is the confirm() method supported in all web browsers?
Yes, the `confirm()` method is supported in all major web browsers, ensuring consistent behavior across different platforms.
๐ŸŒ
scaler.com
scaler.com โ€บ home โ€บ topics โ€บ javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
What happens if a user clicks "OK" in the confirmation dialog?
If a user clicks `OK`, the `confirm()` method returns `true`, indicating that the user has confirmed the action.
๐ŸŒ
scaler.com
scaler.com โ€บ home โ€บ topics โ€บ javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Window โ€บ confirm
Window: confirm() method - Web APIs - MDN Web Docs
window.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-window-confirm-method
Javascript Window confirm() Method - GeeksforGeeks
July 12, 2025 - The confirm() method in JavaScript displays a dialog box with a message and two buttons: OK and Cancel. It is often used to get user confirmation before an action, returning true if OK is clicked, and false if Cancel is clicked.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ javascript โ€บ window โ€บ confirm()
JavaScript | window | confirm() | Codecademy
June 17, 2023 - ... The following example uses the confirm() function to ask the user if they wish to exit the page. It uses an if statement to control how the function performs based on the input.
๐ŸŒ
JavaScript.info
javascript.info โ€บ tutorial โ€บ the javascript language โ€บ javascript fundamentals
Interaction: alert, prompt, confirm
The second parameter is optional, but if we donโ€™t supply it, Internet Explorer will insert the text "undefined" into the prompt. ... The function confirm shows a modal window with a question and two buttons: OK and Cancel.
๐ŸŒ
Envato Tuts+
code.tutsplus.com โ€บ home โ€บ coding fundamentals
Confirm Yes or No With JavaScript | Envato Tuts+ - Code
July 21, 2021 - So thatโ€™s how you can use the confirm method in JavaScript to present a yes or no selection dialog box. There are some drawbacks of using the confirm method to get user confirmation. One is that the confirmation dialog will not be part of your app or website's UI. It will not use your branding or color scheme. It also cannot be customized, for example if you want to say Yes or No instead of OK and Cancel.
Find elsewhere
๐ŸŒ
Michael-thomas
michael-thomas.com โ€บ tech โ€บ javascript โ€บ ex_confirm.htm
Confirm() JavaScript Function - Michael Thomas
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_continu...
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
January 2, 2024 - The confirm() method prompts the user to submit the form and records their choice in userChoice. If the user selects OK, an alert confirms the successful submission, and the form is manually submitted.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ tryit.asp
JavaScript Confirm Box
The W3Schools online code editor allows you to edit code and view the result in your browser
๐ŸŒ
PHPpot
phppot.com โ€บ javascript โ€บ javascript-confirm
JavaScript Confirm Dialog Box with Yes No Alert - PHPpot
This tutorial will explain more about this JavaScript basic concept with examples. This quick example shows the JS script to do the following. It shows a confirm box with a consent message passed as an argument to the confirm() function.
๐ŸŒ
Tizag
tizag.com โ€บ javascriptT โ€บ javascriptconfirm.php
Javascript Tutorial - Confirm
Learn how to create a confirm javascript popup box with Tizag.com's Javascript Confirm lesson.
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ javascript bom โ€บ javascript confirm
JavaScript confirm
December 17, 2023 - The question is an optional string to display in the dialog. The result is a Boolean value indicating whether the OK or Cancel button was clicked. If the OK button is clicked, the result is true; otherwise, the result is false.
๐ŸŒ
BitDegree
bitdegree.org โ€บ learn โ€บ javascript-confirm
Usage of JavaScript Confirm Method: Confirm Message Explained
September 8, 2017 - The confirm() method returns true when users click OK, and false when they click CANCEL or X. This function displays a message in a dialog box. Nowadays, website owners are always aiming to make their pages user-friendly.
๐ŸŒ
Quackit
quackit.com โ€บ javascript โ€บ codes โ€บ javascript_confirm.cfm
JavaScript Confirm
The JavaScript confirm box gives your users a chance to confirm an action before JavaScript runs it. The 'confirm' box is created using JavaScript's built-in confirm() function.
๐ŸŒ
Daypilot
code.daypilot.org โ€บ 67418 โ€บ javascript-confirm-replacement
JavaScript confirm() Replacement | DayPilot Code
JavaScript confirm(): var result = confirm("Are you sure?"); if (result) { console.log("confirmed"); } DayPilot.Modal.confirm(): DayPilot.Modal.confirm("Are you sure?").then(function(modal) { if (modal.result) { console.log("confirmed"); } }); DayPilot.Modal.confirm() using async/await syntax: ...
๐ŸŒ
Code.mu
code.mu โ€บ en โ€บ javascript โ€บ book โ€บ prime โ€บ conditions โ€บ confirm
confirm function in JavaScript
let ok = confirm('The question text'); if (ok) { console.log('You answered yes'); } else { console.log('You answered no'); }
๐ŸŒ
Telerik
telerik.com โ€บ forums โ€บ javascript-confirm-are-you-sure-not-triggering-click-event-when-true
Javascript Confirm 'Are you sure?' not triggering click event when true in UI for ASP.NET AJAX | Telerik Forums
Strangely, when I remove the 'return' from "return addGroup();" it will trigger my server side click event whether I say yes or no to the confirm. Am I making some fundamental JavaScript mistake? function addGroup() { var addgroupbutton = document.getElementById('<%= btnAddGroup.ClientID %>'); var changegroupbutton = document.getElementById('<%= btnSave.ClientID %>'); if (confirm('Are you sure you want to add a new group?')) { addgroupbutton.disabled = true; changegroupbutton.disabled = false; alert("1"); return true; } else { alert("2"); addgroupbutton.disabled = false; changegroupbutton.disa
๐ŸŒ
Code.mu
code.mu โ€บ en โ€บ javascript โ€บ manual โ€บ dialog โ€บ confirm
The confirm function - box with a confirmation button in JavaScript
The confirm function calls up a confirmation box with OK and Cancel buttons. Returns true if the OK button was pressed, and false if the Cancel button was pressed.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 645424 โ€บ languages โ€บ JS-Confirm-Box-Working
JS Confirm Box Not Working (HTML Pages with CSS and JavaScript forum at Coderanch)
I'm working on a JavaScript confirm box for a contact form I have constructed, but it is most definitely not working. (Everything else but the confirm form works, by the way.) I think I need a (a few) fresh pair(s) of eyes to take a look at what I've got so far. I've tried moving var r to the top with everything else, and I've tried keeping it with in its own if ...