niutech / showModalDialog

window.showModalDialog polyfill using a <dialog> element
https://niutech.github.io/showModalDialog/demo.html
Apache License 2.0
177 stars 88 forks source link

How to close the dialog on submit? #13

Closed Viveksubramani closed 9 years ago

Viveksubramani commented 9 years ago

i have a form in the dialog and i wanted to close the dialog after I submitted it. Is it possible?

niutech commented 9 years ago

You can do this from inside the modal:

document.getElementsByTagName('form')[0].addEventListener(function(e) {
    e.preventDefault();
    //send the form data
    var req = new XMLHttpRequest();
    req.send(new FormData(this));
    //or return some input field value
    returnValue = document.getElementsByTagName('input')[0].value;
    parent.document.getElementsByTagName('dialog')[0].close();
});