473,657 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prompt and alert under conditions

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 (null.html)
opens. Or,
2. He gives a wrong answer and an Alert pops-up, with "This is not the right
answer!" in it. So, he clicks Alert's OK button and the Prompt box re-opens
automatically. However, after three wrong answers a new page (sorry.html)
opens. Or,
3. When he gives the correct answer a new page (correct.html) opens.

Can someone help me please? Or am I asking too much?

--
Merlin dying to the Lady of the Lake:
"We lived our lives with passion and devotion"
--
Please, remove the TRAP to contact me
--
Jul 23 '05 #1
7 1547
On Wed, 29 Sep 2004 01:26:20 +0300, geotso wrote:
2. He gives a wrong answer and an Alert pops-up, ...


2b. Whereupon he calls her, who (she) decodes the JS
and tells him the password.

2c. Site cracked! ;-)

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #2
Andrew Thompson wrote:
On Wed, 29 Sep 2004 01:26:20 +0300, geotso wrote:
2. He gives a wrong answer and an Alert pops-up, ...


2b. Whereupon he calls her, who (she) decodes the JS
and tells him the password.

2c. Site cracked! ;-)


I know, I know... However it isn't a site. Is just a book for my little son.
So, can you help me now please?

Thanks.

BTW, sorry for I'm late. There was a problem with my ISP...
Jul 23 '05 #3
On Wed, 29 Sep 2004 18:08:07 +0300, geotso wrote:
Andrew Thompson wrote:
On Wed, 29 Sep 2004 01:26:20 +0300, geotso wrote:
2. He gives a wrong answer and an Alert pops-up, ...
... 2c. Site cracked! ;-)


I know, I know... However it isn't a site. Is just a book for my little son.
So, can you help me now please?


Given I have never had need for such protection, no.
You might start with Google, though..
<http://www.google.com/search?q=javasc ript+password+d ownload>

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #4
Lee
geotso said:

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 (null.html)
opens. Or,
2. He gives a wrong answer and an Alert pops-up, with "This is not the right
answer!" in it. So, he clicks Alert's OK button and the Prompt box re-opens
automaticall y. However, after three wrong answers a new page (sorry.html)
opens. Or,
3. When he gives the correct answer a new page (correct.html) opens.

Can someone help me please? Or am I asking too much?


<html>
<head>
<title>Demo</title>
<script type="text/javascript">
var attempts=3;
var question="What' s your favorite color?";
var answer="blue";
function guard(){
while (attempts-->0) {
var response = prompt(question ,"");
if (!response) {
location = "null.html" ;
}else if (response==answ er) {
location = "correct.ht ml";
} else {
alert("This is not the right answer!");
}
}
location="sorry .html";
}
</script>
</head>
<body onload="guard() ">
<p>This page is blank</p>
</body>
</html>

Jul 23 '05 #5
Lee wrote:

<html>
<head>
<title>Demo</title>
<script type="text/javascript">
var attempts=3;
var question="What' s your favorite color?";
var answer="blue";
function guard(){
while (attempts-->0) {
var response = prompt(question ,"");
if (!response) {
location = "null.html" ;
}else if (response==answ er) {
location = "correct.ht ml";
} else {
alert("This is not the right answer!");
}
}
location="sorry .html";
}
</script>
</head>
<body onload="guard() ">
<p>This page is blank</p>
</body>
</html>


Lee,

Thank you very much for your try!

However:
I can't access the "correct.ht ml, since after the right answer ("blue"), the
Prompt box pops-up again, the cursor looks busy, and the status bar tells me
that IE tries to open the "correct.ht ml". Furthermore, even after three
right answers I go to the "sorry.html ".

I have to click three times the Cancel before I go to "sorry.html ". Can this
be done after only one click?

BTW I call the function from a button with onClick and not at the onLoad
time as in your example. Could this cause the described problems?

Thanks again for your patience!
Jul 23 '05 #6
Lee
geotso said:

Lee wrote:

<html>
<head>
<title>Demo</title>
<script type="text/javascript">
var attempts=3;
var question="What' s your favorite color?";
var answer="blue";
function guard(){
while (attempts-->0) {
var response = prompt(question ,"");
if (!response) {
location = "null.html" ;
}else if (response==answ er) {
location = "correct.ht ml";
} else {
alert("This is not the right answer!");
}
}
location="sorry .html";
}
</script>
</head>
<body onload="guard() ">
<p>This page is blank</p>
</body>
</html>


Lee,

Thank you very much for your try!

However:
I can't access the "correct.ht ml, since after the right answer ("blue"), the
Prompt box pops-up again, the cursor looks busy, and the status bar tells me
that IE tries to open the "correct.ht ml". Furthermore, even after three
right answers I go to the "sorry.html ".

I have to click three times the Cancel before I go to "sorry.html ". Can this
be done after only one click?


The problem is that I dislike Internet Explorer so much
these days that I don't generally bother to test in it.

This version works in IE as well as in decent browsers:
<script type="text/javascript">
var attempts=3;
var question="What' s your favorite color?";
var answer="blue";
var newpage="sorry. html";
function guard(){
while (attempts-->0) {
var response = prompt(question ,"");
if (!response) {
newpage = "null.html" ;
break;
}else if (response==answ er) {
newpage = "correct.ht ml";
break;
} else {
alert("This is not the right answer!");
}
}
location=newpag e;
}
</script>

Jul 23 '05 #7
my goodness!

thank you so much, Lee!
Jul 23 '05 #8

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

Similar topics

1
2814
by: Cooper | last post by:
Hello, i have a form with TEXT, SELECT etc, elements. Simple, i suppose two TEXT (name: T1 and T2). If a user insert a bad value, it display a error message and turn back at form. My problem is: I am in T1, i insert a bad value... is displayed a alert, i click on OK and prompt go in T2. Now, i want to do that if i am in T1 after that i click OK in alert window, the prompt turn in T1 and not go in T2. I hope that i have explained my...
2
2829
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 problems with the font used to present messages in alert, prompts and confirm dialogs. If I for examle paste a chinese value in a prompt dialog it is shown om my machine as a vertical bar. When I write the value back to a textbox <input type="text"...
2
1576
by: Grey | last post by:
I need to prompt out an alert box when I finished some server programming in ASP.NET. But I don't know how. Please advise me the way. Million Thanks
3
7884
by: J.P. Cummins | last post by:
In my ASP.NET application, I wish to have a page for administrators to edit items in a list. Preferably, I would like to use the javascript prompt for the 'rename' function, and a javascript alert box for the 'delete' function. When the user clicks 'rename', the javascript prompt asks for the new name. When the user clicks 'delete', a javascript alert asks the user if he really wants to delete that item. Here is an example of what my...
8
12278
by: lisaj | last post by:
I'm having huge difficulties producing a script for this: Write a javascript programme that will prompt for, and accept from the user, an input string which contains at least 8 characters. It should then prompt for and accept a numerical value that is no greater than the length of the input string and should output a version of the input string which takes the form of a string of the same length as the input string but consisting entirely of...
1
1591
by: andwing | last post by:
<form method="post" name="folder" id="folder"> <input type="hidden" name="name" value="" /> <input name="submit" type="hidden" value="new name .." onclick="getname();" /> function getname () { document.folder.name.value = prompt ('welcome: ', 'default');
5
3915
by: hcross | last post by:
This project is a web based html and Javascript site. I am working on mac at the moment. This script works except for attempting to open new window once complete. As you can see, i am new to javascript coding. Can i open a new browser window after my prompts and alerts have finished. I am not sure what i am doing wrong. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
5
6280
by: vjsv2007 | last post by:
Can you help to make one alert with all details? <script type="text/javascript"> <!-- function validate_form ( ) { valid = true;
2
3342
Computer Guru
by: Computer Guru | last post by:
Prompts and alerts are usually one lined. However, my prompt statement is rather long and does not fit on one line. With js alerts I use something like this... <a href="javascript:alert('a'+'\n'+2+'\n'+'b');">test</a> but this doesn't seem to work with my prompt. <script> function ask()
0
8420
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
8324
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
8842
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
8740
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
8516
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
7353
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...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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
4330
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.