473,383 Members | 1,821 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,383 software developers and data experts.

Prompt window - OK/Cancel in Do While

My question is closely related to http://www.thescripts.com/forum/thread444945.html and was not answered there, so I figured I'd revive it since I think I have the same issue.

Here is my applicable code:
Expand|Select|Wrap|Line Numbers
  1.   do {
  2.    var f=prompt('Would you like the output to be displayed in this page (1) or as a pop-up (2)','1');
  3.     }
  4.   while (f != "1" && f != "2" && f != "");
  5.  
  6. // Begin case statement to make the code do its stuff based on "f"
Basically I want the prompt to get the user to have to put in either a 1 or a 2 no matter what, unless they hit Cancel. That means if they erase my "1" I have in there by default and they leave the prompt blank and they hit OK, I want it to spit the prompt back at them. The code above works great for that except the Cancel will just make the box stay up. I know that it's because of my f != "" above (the element that checks to see if the box was left blank), but is there a way to distinguish between when f happens to be null from being left blank (f's value is actually "undefined") and when the Cancel button was pressed (when f's value is "null")? Is there actually a difference? Using f !="null" above does not work, either.

Thanks,
Tom
Aug 28 '07 #1
4 2864
epots9
1,351 Expert 1GB
try this:

Expand|Select|Wrap|Line Numbers
  1. var f = "";
  2. do {
  3. f=prompt('Would you like the output to be displayed in this page (1) or as a pop-up (2)','1');
  4. }
  5. while (f != "1" || f != "2" || f == "");
  6.  
i might have missed read your question, but does that do what you want?

good luck
Aug 28 '07 #2
phvfl
173 Expert 100+
Hi Tom,

When cancel is pressed the returned value (f) is null. This can be seen by changing the code to:
Expand|Select|Wrap|Line Numbers
  1. do {
  2. var f=prompt('Would you like the output to be displayed in this page (1) or as a pop-up (2)','1');
  3. alert(f);
  4. }
  5. while (f != "1" && f != "2" && f != "");
  6.  
  7. // Begin case statement to make the code do its stuff based on "f"
  8.  
The additional line simply alerts you to the value if f so that you can see what the output is. The code should work as you wish using:
Expand|Select|Wrap|Line Numbers
  1. do {
  2. var f=prompt('Would you like the output to be displayed in this page (1) or as a pop-up (2)','1');
  3. }
  4. while (f != "1" && f != "2" && f != null);
  5.  
  6. // Begin case statement to make the code do its stuff based on "f"
  7.  
The other effect is that the prompt is not removed when the content is deleted as previously.
Aug 28 '07 #3
pbmods
5,821 Expert 4TB
Heya, Tom. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 28 '07 #4
epots9, not quite - the prompt never ends when you have "or" statements between it all. Thanks for trying, though.

Mods - sorry - forgot to look at that section...

But phvfl, you're awesome, thank you - your code worked great. I had posted an alert on "f" before and it told me what the values of it were and all, but I thought I had to have quotes on the "null" - guess I didn't! Was beating my head up against the wall on this for too long to see the obvious. Thanks again, all.

-Tom
Aug 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Gord | last post by:
Hello, If you set the flag for an overwrite prompt using the 'Save' common dialog, how do you read the response when the user clicks the Yes or No in the 'overwrite' message box? Everything...
6
by: chon | last post by:
I have an ASP page that is sent a file location as a parameter. It opens this file, loads the ADODB.Stream object and does a binary write to the page forcing the download dialog to appear. This...
7
by: geotso | last post by:
Hi. I'm looking for a javascript for the following scenario: The visitor clicks a button and a Prompt box appears, where: 1. He clicks the Cancel button, typing nothing and a new page...
7
by: Petesman | last post by:
I am trying to make a prompt that will ask the user for some input... If I just use var input = prompt("dafa") everything works fine but the box is put in the top left corner of the window. I need...
3
by: sancha | last post by:
Hi, I need to promt the user when he moves away from the page by clicking an of the links available on the page. I was trying to use the onbeforeunload function but it seems it is a jScript...
2
by: Hans | last post by:
Hi! I have an asp application where I use a lot of javascript for validations etc and as it is today I use alert, confirm and prompt dialogs. Now we are adding support for unicode and I have...
4
by: louise raisbeck | last post by:
I have this scenario (simplified) function addnewdata () { check for partial match already in db for information entered by user if (partialmatch succeeds) { open new window aspx page (using...
2
gregerly
by: gregerly | last post by:
I'm working on a corporate intranet site and am trying to create a page that will warn a user on window unload if they have not saved thier work. Basically I just select all inputs, and on change,...
1
by: ramprakashjava | last post by:
hi , i hav this error while running this customerDetails.jsp <html:html> <head> <html:base/> </head> <body> <html:errors/> <html:form...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.