Click to See Complete Forum and Search --> : Checking input on closing of Modal Window


anifled
12-11-2003, 08:01 PM
I have a modal window. On closing the window (using the X) I want to be able to check if data has been input. If it hasn't I want to stop the closing and have the user input the needed data. If I could disable the X that would solve my problem. According to my searches that is not possible. Anyway here is my code. Can anyone help?

<html>
<head>
<title> AE Reason for Denial </title>
<link rel="stylesheet" type="text/css" href="css/main.css"/>

<script language="javascript">

var callerWindowObj = dialogArguments;

function passData() {
/*
*@ Grab the data from current popup.
*/
var vInput = null;
var V55 = eval("document.forms[0].P_RAD1");
if(V55[0].checked) {
vInput = V55[0].value;
}
else if (V55[1].checked) {
vInput = V55[1].value;
}
else if(V55[2].checked) {
if(document.forms[0].P_TXT1.value=="") {
alert('Please enter Other reasons for denial');
return;
}
else {
vInput = document.forms[0].P_TXT1.value;//V5[2].value;
}
}
else {
alert("Please select one option");
return;
}
/*
*@@ Push the data to opener.
*/
// var callerWindowObj = dialogArguments;
// var vVal = window.opener.document.forms[0].flag.value;
var vVal = callerWindowObj.document.forms[0].flag.value;
// window.opener.document.forms[0].bFlag.value = "Y";
callerWindowObj.document.forms[0].bFlag.value = "Y";
// var doc = window.opener.document;
var doc = callerWindowObj.document;
var oTbl = doc.getElementById("tbl22");
oTbl.setAttribute("border","0");
oTbl.setAttribute("bgColor","#DEE8FF");
var tbl = doc.getElementById("tbl88");
v1 = doc.createElement("TR");
v2 = doc.createElement("TD");
v2.innerHTML = vVal;
v3 = doc.createElement("TD");
v3.innerHTML = vInput;
v1.appendChild(v2);
v1.appendChild(v3);
tbl.appendChild(v1);
/*
*@@@ Close the current window.
*/
window.close();
}//end function

function selectOption(fFiled) {
if(typeof(fFiled) == "string") {
var sF = fFiled.substring(0,fFiled.indexOf(','));
var sVal = fFiled.substring(fFiled.indexOf(','+1,fFiled.length);
//alert("F "+sF+" V "+sVal);
var Obj = eval("document.forms[0]."+sF);

if(typeof(Obj) == "object") {
for(var k=1;k<Obj.length;k++) {
//alert("VAL "+Obj[k].value);
if (Obj[k].value==sVal) {
// alert("inside");
Obj[k].checked = true;
}//if
}//for
}//if
}//if
}//selectOption

function postClose() {
// window.opener.document.forms[0].bFlag.value = "Y";
callerWindowObj.document.forms[0].bFlag.value = "Y";
}


</script>
</head>
<body onUnLoad="javascript:postClose();">
<form name="pvcform">
<table width="250" cellspacing="0" cellpadding="0">
<tr>
<td WIDTH="250" class="subsectionHdr" align="left" >Please select/enter reason for denial</td>
</tr>
<tr>
<td WIDTH="250" class="subsectionHdr">

<input type="radio" name="P_RAD1" value="Exceeds working hours"/>Exceeds working hours<BR/>

<input type="radio" name="P_RAD1" value="Exceeds admin time allowed"/>Exceeds admin time allowed<BR/>

<input type="radio" name="P_RAD1" checked value="Other"/>Other<BR/>

<TEXTAREA ROWS="5" NAME="P_TXT1" COLS="25" onKeyPress="javascript:selectOption('P_RAD1,Other');" ></TEXTAREA> <BR/><BR/>

<input type="button" value="OK" onClick="javascript:passData();"/>

<input type="reset" value="Clear"/>
</td>
</tr>
</table>
</form>
</body>
</html>

olaf
12-12-2003, 05:49 AM
Hallo,

I think if the user hits the X in the upper right corner does it "Game over".

But maybe it helps if you put in some validation ( if var is not set ) in the postClose function. Use a confirm for the interaction.

mitya
12-12-2003, 05:53 AM
The thing to remember here is you cannot physically force someone to do something. They're on your site out of choice and if they want to close the modal, they will. You can only persuade and convince them :)

As for grabbing the value, just call it as per any other property check, i.e.

document.all.formfield.value

then return it to your parent page using either RETURN or specifying the value as a targeted var.

anifled
12-12-2003, 02:48 PM
I figured out on how to sort of do it. I use onbeforeunload and check my input. If there is no input and the X is clicked the user is informed that there is no input. Unfortunatley, then a "built in" alert appears asking the user if they want to leave the page or stay on it.

Does anyone know of a way to surpress the "built in" alert?

anifled
12-12-2003, 06:52 PM
I did some research on this. There doesn't appear to be a way to disable the alert. Correct me if I am wrong. But, a custom message can be added to that alert.

window.onbeforeunload = bunload;

function bunload(){
//This function gets called when user closes the window using
//the X button
if ( !(validate()) ) //validate the form
{
mess = "Please enter Other reasons for denial";
return mess;
}
}

mitya
12-13-2003, 05:01 AM
parent windows cannot be closed automatically, the user is always asked. windows which are open as the result of a link on another page, or pop-up windows, can be closed without prompt.

anifled
12-15-2003, 02:37 PM
How would you close a window that was called by another window without a prompt? Especially how would you do that using the x? Can you give an example?

olaf
12-16-2003, 01:06 AM
just window.close()

anifled
12-16-2003, 11:52 AM
I was looking for how to do the following which:

parent windows cannot be closed automatically, the user is always asked. windows which are open as the result of a link on another page, or pop-up windows, can be closed without prompt.


window.close() closes the window. I am looking for something that when a popup or window is closed using the X(which is the close button on the titlebar) I won't be prompted asking if I want to close.

olaf
12-18-2003, 09:57 AM
I posted an answer before:

the X-button = "Game over"

this button ends the browser-application and not the window