Hi,
This is sort of a :
How to build a Yes/No dialog box qquestion.
Or perhaps a question about getting javascript variables
from a pop-up window and processing them on a submit.
This is what I'd like to have happen :
When the user clicks on the Delete button the confirm() method
should run and prompt the user for a Yes/No selection. Then
the doDelete variable should get assigned. Then the validate()
method should get called. The result of validate() should be
false if the user selected "No".
This is what happens :
confirm runs and prompts the user. The validate() method never
sees the value of doDelete.
Notice there are two forms.
Your help is appreciated. Thanks!
<html>
<head>
<script>
var winConfirm = null;
var buttonNum = 0;
var doDelete = "No";
function confirm()
{
var windowWidth = 250;
var windowHeight = 100;
var locX = ( screen.width - windowWidth ) / 2;
var locY = ( screen.height - windowHeight ) / 2;
var windowFeatures = "width=" + windowWidth
+ ",height=" + windowHeight
+ ",screenX=" + locX
+ ",screenY=" + locY
+ ",titlebar=no"
+ ",left=" + locX
+ ",top=" + locY;
if ( ( winConfirm != null ) && !winConfirm.closed ) {
winConfirm.close();
}
winConfirm = window.open( "", "winConfirm", windowFeatures );
var theHTML = '<head><title>Confirm Deletion</title>'
+ '<body bgcolor="#cccccc">'
+ '<center><font="Verdana, Arial"><b>'
+ 'Really Delete ?'
+ '</b><form name="buttonForm">'
+ '<input type="button" value=" Delete "'
+ ' onclick="opener.buttonClicked(0);self.close();">'
+ ' '
+ '<input type="button" value=" Cancel "'
+ ' onclick="opener.buttonClicked(1);self.close();">'
+ '</form></center></font></body>';
winConfirm.document.writeln( theHTML );
alert("Flow shouldn't get here until after the user has selected Yes
or No. How to make it wait for Yes/No ?");
}
function buttonClicked( buttonChoice )
{
switch( buttonChoice )
{
case 0:
doDelete = "Yes";
break;
default:
doDelete = "No";
}
}
function validate(aForm) {
alert("in validate");
if (buttonNum < 2 ) {
aForm.submit();
}
if (doDelete == "No") {
return false;
}
aForm.submit();
}
</script>
</head>
<body>
<form name="aForm" onsubmit="return validate(this);">
<hidden value="2" name="id">
<input type="submit" onclick="buttonNum=0;" value="Edit"><br>
<input type="submit" onclick="buttonNum=1;" value="Send"><br>
<input type="submit" onclick="buttonNum=2;confirm();"
value="Delete"><br>
</form>
<p>
<form name="aForm" onsubmit="return validate(this);">
<hidden value="3" name="id">
<input type="submit" onclick="buttonNum=0;" value="Edit"><br>
<input type="submit" onclick="buttonNum=1;" value="Send"><br>
<input type="submit" onclick="buttonNum=2;confirm();"
value="Delete"><br>
</form>
</body>
</html>