| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/returnValue | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since March 2022.
The returnValue property of the HTMLDialogElement interface is a string representing the return value for a <dialog> element when it's closed.
You can set the value directly (dialog.returnValue = "result") or by providing the value as a string argument to close() or requestClose().
A string representing the returnValue of the dialog.
Defaults to an empty string ("").
The following example displays a button to open a dialog. The dialog asks the user if they want to accept a Terms of Service prompt.
The dialog contains "Accept" or "Decline" buttons: when the user clicks one of the buttons, the button's click handler closes the dialog, passing their choice into the close() function. This assigns the choice to the dialog's returnValue property.
In the dialog's close event handler, the example updates the main page's status text to record the returnValue.
If the user dismisses the dialog without clicking a button (for example, by pressing the Esc key), then the return value is not set.
<dialog id="dialog">
<p>Do you agree to the Terms of Service (link)?</p>
<button id="decline" value="declined">Decline</button>
<button id="accept" value="accepted">Accept</button>
</dialog>
<button id="open">Open dialog</button>
<pre id="log"></pre>
#log {
height: 170px;
overflow: scroll;
padding: 0.5rem;
border: 1px solid black;
}
const logElement = document.getElementById("log");
function log(text) {
logElement.innerText = `${logElement.innerText}${text}\n`;
logElement.scrollTop = logElement.scrollHeight;
}
const dialog = document.getElementById("dialog");
const openButton = document.getElementById("open");
const declineButton = document.getElementById("decline");
const acceptButton = document.getElementById("accept");
openButton.addEventListener("click", () => {
// Reset the return value on each open
dialog.returnValue = "";
updateReturnValue();
// Show the dialog
dialog.showModal();
});
function closeDialog(event) {
const button = event.target;
dialog.close(button.value);
}
function updateReturnValue() {
log(`Return value: "${dialog.returnValue}"`);
}
declineButton.addEventListener("click", closeDialog);
acceptButton.addEventListener("click", closeDialog);
dialog.addEventListener("close", updateReturnValue);
Click "Open Dialog", then choose the "Accept" or "Decline" buttons in the dialog, or dismiss the dialog by pressing the Esc key. Observe the different status updates.
| Specification |
|---|
| HTML # dom-dialog-returnvalue-dev |
<dialog> elementThis page was last modified on Jan 26, 2026 by MDN contributors.
HTMLDialogElementBeforeUnloadEventDOMStringMapErrorEventHTMLAnchorElementHTMLAreaElementHTMLAudioElementHTMLBRElementHTMLBaseElementHTMLBodyElementHTMLButtonElementHTMLCanvasElementHTMLDListElementHTMLDataElementHTMLDataListElementHTMLDivElementHTMLDocumentHTMLElementHTMLEmbedElementHTMLFieldSetElementHTMLFormControlsCollectionHTMLFormElementHTMLFrameSetElementHTMLGeolocationElementHTMLHRElementHTMLHeadElementHTMLHeadingElementHTMLHtmlElementHTMLIFrameElementHTMLImageElementHTMLInputElementHTMLLIElementHTMLLabelElementHTMLLegendElementHTMLLinkElementHTMLMapElementHTMLMediaElementHTMLMenuElementHTMLMetaElementHTMLMeterElementHTMLModElementHTMLOListElementHTMLObjectElementHTMLOptGroupElementHTMLOptionElementHTMLOptionsCollectionHTMLOutputElementHTMLParagraphElementHTMLPictureElementHTMLPreElementHTMLProgressElementHTMLQuoteElementHTMLScriptElementHTMLSelectElementHTMLSourceElementHTMLSpanElementHTMLStyleElementHTMLTableCaptionElementHTMLTableCellElementHTMLTableColElementHTMLTableElementHTMLTableRowElementHTMLTableSectionElementHTMLTemplateElementHTMLTextAreaElementHTMLTimeElementHTMLTitleElementHTMLTrackElementHTMLUListElementHTMLUnknownElementHTMLVideoElementHashChangeEventHistoryImageDataLocationMessageChannelMessageEventMessagePortNavigatorPageRevealEventPageSwapEventPageTransitionEventPluginPluginArrayPromiseRejectionEventRadioNodeListTimeRangesUserActivationValidityStateWindowWorkletGlobalScopeYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |