473,766 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.clo sed ) {
winConfirm.clos e();
}

winConfirm = window.open( "", "winConfirm ", windowFeatures );

var theHTML = '<head><title>C onfirm Deletion</title>'
+ '<body bgcolor="#ccccc c">'
+ '<center><font= "Verdana, Arial"><b>'
+ 'Really Delete ?'
+ '</b><form name="buttonFor m">'
+ '<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.docu ment.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="retur n validate(this); ">
<hidden value="2" name="id">
<input type="submit" onclick="button Num=0;" value="Edit"><b r>
<input type="submit" onclick="button Num=1;" value="Send"><b r>
<input type="submit" onclick="button Num=2;confirm() ;"
value="Delete"> <br>
</form>
<p>
<form name="aForm" onsubmit="retur n validate(this); ">
<hidden value="3" name="id">
<input type="submit" onclick="button Num=0;" value="Edit"><b r>
<input type="submit" onclick="button Num=1;" value="Send"><b r>
<input type="submit" onclick="button Num=2;confirm() ;"
value="Delete"> <br>
</form>

</body>
</html>

Aug 16 '05 #1
4 4938
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.clo sed ) {
winConfirm.clos e();
}

winConfirm = window.open( "", "winConfirm ", windowFeatures );

var theHTML = '<head><title>C onfirm Deletion</title>'
+ '<body bgcolor="#ccccc c">'
+ '<center><font= "Verdana, Arial"><b>'
+ 'Really Delete ?'
+ '</b><form name="buttonFor m">'
+ '<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.docu ment.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="retur n validate(this); ">
<hidden value="2" name="id">
<input type="submit" onclick="button Num=0;" value="Edit"><b r>
<input type="submit" onclick="button Num=1;" value="Send"><b r>
<input type="submit" onclick="button Num=2;confirm() ;"
value="Delete"> <br>
</form>
<p>
<form name="aForm" onsubmit="retur n validate(this); ">
<hidden value="3" name="id">
<input type="submit" onclick="button Num=0;" value="Edit"><b r>
<input type="submit" onclick="button Num=1;" value="Send"><b r>
<input type="submit" onclick="button Num=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="button Num=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("cancelle d");
return false;
}
alert("Submit") ;
aForm.submit();
}
</script>
</head>
<body>
<form name="aForm" onsubmit="retur n validate(this); ">
<hidden value="2" name="id">
<input type="submit" onclick="button Num=0;" value="Edit"><b r>
<input type="submit" onclick="button Num=1;" value="Send"><b r>
<input type="submit" onclick="button Num=2; doDelete=confir m('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.c om> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.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.clo sed ) {
winConfirm.clos e();
}

if(buttonNum==2 )
{
buttonNum=0; // Prepare for subsequent call

rv=false // Cancel submit and let opener.buttonCl icked DECIDE

winConfirm = window.open( "", "winConfirm ", windowFeatures );

var theHTML = '<HTML><head><t itle>Confirm Deletion</title></HEAD>'
+ '<body bgcolor="#ccccc c">'
+ '<center><font= "Verdana, Arial"><b>'
+ 'Really Delete ?'
+ '</b><form name="buttonFor m">'
+ '<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.docu ment.open();
winConfirm.docu ment.writeln( theHTML );
winConfirm.docu ment.close();

}

return rv;
}

function buttonClicked( buttonChoice )
{
if(buttonChoice ==0)
document.forms. aForm.submit();
}

</script>
</head>
<body>

<form name="aForm" onsubmit="retur n confirm(this);" >
<input type="submit" onclick="button Num=0;" value="Edit"><b r>
<input type="submit" onclick="button Num=1;" value="Send"><b r>
<input type="submit" onclick='button Num=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
1757
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 rest of the page - (just some simple html). Else no, they might see a message that says "go back". I need the simplest briefest example - Thanks
10
4228
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 password with a password dialog box . ----------------------- |
2
30164
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.) and would like to make the dialog look and act like the standard MessageBox. Therefore, I would like to put in the message section the same type of icons found in the MessageBox dialog, such as MessageBoxIcon.Exclamation. In another post here I had...
1
2537
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 dialog box? What about just changing the print dialog box used by Internet Explorer?
1
1090
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
1253
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 file and also select a location to save it in. I then would like to grab the path and file name information and use that to save the dataset. PLS help I will be forever grateful. Thanks
6
2099
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. "This page contains both secure and nonsecure items. Do you want to display the nonsecure items." It was not happening before. I have searched in internet for removing the dialog box. This is the solution that I got
6
4056
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 instantiating a particular class in my project but the dialog doesn't tell me what code in the class is causing the problem (and it a large class). How can I get the IDE to take me to the offending line of code? If I put this line in my...
0
1246
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 control multiple copy printing, however, there must be some structure that is passed from the print dialog box to the driver. I need this to accuratly track printer usage. I found a structure that may be what is passed, but I don't know how to...
2
10995
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 "Save As" dialog and the ability to grab the filepath so that the second export appends to it. Anyway, I found Microsofts method and it works, except that I can't figure out how to populate the File Name box in the Dialog with a default name (say,...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.