473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Create Yes/No dialog box; Getting JS values from pop-up window on submit

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();">'
+ '&nbsp;'
+ '<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>

Aug 16 '05 #1
4 4908
Hi,
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();">'
+ '&nbsp;'
+ '<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>


There is a Javascript-Function called confirm() which opens a small Box with OK-
and Cancel-Buttons, you can set the text, the return value is true (OK) or false
(Cancel). So writing

<input type="submit" onclick="buttonNum=2;doDelete=confirm('Really Delete ?');"

should do what you're looking for. (your confirm()-function isn't needed in that
case so here's the complete example:

<html>
<head>
<script type="text/javascript">
var buttonNum = 0;
var doDelete = false;

function validate(aForm) {
alert("in validate");
if (buttonNum < 2 ) {
alert("Submit");
aForm.submit();
}
if (!doDelete) {
alert("cancelled");
return false;
}
alert("Submit");
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; doDelete=confirm('Really delete?');"
value="Delete"><br>
</form>

</body>
</html>

cu

martin
Aug 16 '05 #2
Ooooooooh that's sweet. I'm gonna go with that.

I'd be interested in seeing a solution for the original question
though.
- Having spent a few hours try to get it to work.

Aug 16 '05 #3

<gi*******************@yahoo.com> wrote in message news:11**********************@z14g2000cwz.googlegr 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();">'
+ '&nbsp;'
+ '<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.

Aug 16 '05 #4
Thanks Stephen,

That works and looks great.

You also explained what I didn't know and what I couldn't
figure out on my own.

I totally missed the double call to validate, although I seen it
occur in my sandbox somehow I still missed it. So it goes
when you're spinning your wheels.

Assiging buttonNum to zero. Now that was a good tip.

Letting buttonClicked() handle the submit was something
I wouldn't have thought of doing.

You get my tip of the hat. Wow!

Aug 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hal Halloway | last post by:
Newbie looking for the way have a dialog box and when a user goes to this page they see *nothing*, Except for a dialog box pop, the box says: "are you sure?" Yes/No. If user clicks yes they see the...
10
by: Fred | last post by:
Hi all ! Newbie in C programming needs help please ... I have a Windows console application written in C who ask a password on the command line . I want to change the original code to ask the...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
1
by: John | last post by:
Hello, Is it possible to modify the print dialog box that appears when a user clicks File->Print? Is it possible to make this modification so that all Windows programs use the modified print...
1
by: sun | last post by:
i want to pop a dialog box, but i use asp.net c#, always not realization; who man can tell me why is it? thanks.
1
by: Edward F | last post by:
I am using the following code and it works fine. Instead of hard coding the location for saving the file I will like to use the file dialog box in windows. So that the user and give a name to the...
6
by: pradeep_TP | last post by:
I am facing a strange problem with my web site. Afer reinstalling the web application on the web server, I am getting a dialog box for each page. The dialog box has the following information. ...
6
by: Steve Long | last post by:
Help, I'm running VS.NET 2003 and when I try to start my application, I get the "unhandled exception" dialog instead of the IDE highlighting the offending line of code. The problem appears to be...
0
by: hoderbob | last post by:
I need to find a way to catch the parameters entered in the Print Dialog box of any Windows application and pull the number of copies the user selected. I know most printers allow the driver to...
2
by: vbaDev | last post by:
Hi. I am using Access 2000 and in my code I'm exporting a table into an Excel file (creating it), then the code needs to export another query into the same file (a new worksheet). So I needed both a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.