Reputation: 3698
My site opens a popup when clicking a button, now, the user can click ok or cancel. If Ok, the form in the parent must be sent.
Parent:
<input class="boton" type="button" value="Ok" accesskey="O" onClick="openPopup(,'texto.','Do you want to continue?')"/>
function openPopup
function openPopup(button,textoAlert,subTextoAlert) {
var html = ...
"<input class='botonPopup' type='button' value='Cancel' accesskey='C' onclick=\"window.close('popup');\"/>" +
"<input class='botonPopup' type='button' value='Ok' accesskey='O' onclick=\"window.close('popup'); return true;\"/>"
popup = window.open('','', 'titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no, top=300, left=300, width=484, height=231');
popup.document.write(html);
...
So, when button ok is clicked, I need to use this "true"
How can I do this?
Upvotes: 0
Views: 159
Reputation: 10685
You can use the parent
property to access the parent window (including DOM tree and globally accessible variables).
For example, parent.document.getElementById('...').dostuff
or parent.callback(true)
You would add this to the onclick
handler of your input
elements in the popup window.
Example:
Parent
<script>
function callback(choice) {
alert(choice ? "User hit ok!" : "User hit cancel");
}
</script>
<input class="boton" type="button" value="Ok" accesskey="O" onClick="openPopup(,'texto.','Do you want to continue?')"/>
Popup
function openPopup(button,textoAlert,subTextoAlert) {
var html = ...
"<input class='botonPopup' type='button' value='Cancel' accesskey='C' onclick=\"parent.callback(false); window.close('popup');\"/>" +
"<input class='botonPopup' type='button' value='Ok' accesskey='O' onclick=\"parent.callback(true); window.close('popup');\"/>"
popup = window.open('','', 'titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no, top=300, left=300, width=484, height=231');
popup.document.write(html);
...
Upvotes: 1