<> wrote in message news: oups.com...
>This is sort of a :
>How to build a Yes/No dialog box qquestion.
<SNIP>
I have to assume that you're not happy with the limitations of the JS confirm function, although what you're creating
looks pretty much the same.
validate() is called by the submit handler, however it submits the form, which would cause validate() to be called
again. I'm not sure what result that may have.
Opening a new window does not stall execution of a script, therefore if 'delete' is selected, submission should be made
conditional on the 'yes' being pressed.
The HTML generated had missing <HTML> & </HEAD tags.
Failing to call document.open() before writing the HTML and document.close() thereafter, was causing a wait cursor to
appear constantly.
This minor modification abandons validate() and uses the return value of confirm() to authorise the submit.
If the confirm window is opened, buttonClicked( ) determines the action.
Beware it's a bit sluggish under Mozilla and if 'delete' is clicked twice, Opera doesn't seem to like closing the window
and reopening it. I'm not an avid window opener.
<html>
<head>
<script>
var winConfirm = null;
var buttonNum = 0;
var doDelete = "No";
function confirm()
{
var rv=true;
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();
}
if(buttonNum==2)
{
buttonNum=0; // Prepare for subsequent call
rv=false // Cancel submit and let opener.buttonClicked DECIDE
winConfirm = window.open( "", "winConfirm", windowFeatures );
var theHTML = '<HTML><head><title>Confirm Deletion</title></HEAD>'
+ '<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></HTML>';
winConfirm.document.open();
winConfirm.document.writeln( theHTML );
winConfirm.document.close();
}
return rv;
}
function buttonClicked( buttonChoice )
{
if(buttonChoice==0)
document.forms.aForm.submit();
}
</script>
</head>
<body>
<form name="aForm" onsubmit="return confirm(this);">
<input type="submit" onclick="buttonNum=0;" value="Edit"><br>
<input type="submit" onclick="buttonNum=1;" value="Send"><br>
<input type="submit" onclick='buttonNum=2;' value="Delete"><br>
</form>
</body>
</html>
--
S.C.
|