Click to See Complete Forum and Search --> : Prompt/confirm problems...


Paul Jr
11-17-2003, 08:51 PM
Aight, I was helped with this script before (thanks to all who did), but I'm having another problem. Now, I have it set up so that an alert pops up depending on what you enter in for a name:

<script type="text/javascript">
var name = prompt("Please enter your name","here");
while(!name) name = prompt("Please enter your name:", "here");
if(name=="Paul") {
alert("Welcome, Webmaster Paul"); }
if(name=="Jesse" || name=="jesse") {
alert("Welcome, Brother "+name+"."); }
if(name=="luke" || name=="Luke") {
alert("Hi... "+name+"..."); }
if(name=="" || name=="here") {
var accept = confirm("Please enter a name");
if(accept == true) {
location.reload(); }
else {
self.close(); } }
</script>


I want it to display "Welcome+name", and whatever the user entered, as long as it is not any of the name specified, shows up in the alert box. Like, if you entered will, it would be, "Welcome, Will."

I tried this:

<script type="text/javascript">
var name = prompt("Please enter your name","here");
while(!name) name = prompt("Please enter your name:", "here");
if(name=="Paul") {
alert("Welcome, Webmaster Paul"); }
if(name=="Jesse" || name=="jesse") {
alert("Welcome, Brother "+name+"."); }
if(name=="luke" || name=="Luke") {
alert("Welcome... "+name+"..."); }
if(name=="" || name=="here") {
var accept = confirm("Please enter a name");
if(accept == true) {
location.reload(); }
else {
self.close(); } }
else {
alert("Welcome, "+name+"."); }
</script>

But that will display, "Welcome, Paul." After the first alert.

Jona
11-17-2003, 10:09 PM
Switch() time. ;)


<script type="text/javascript">
var id = "";
var name = prompt("Please enter your name","here");
while(!name) name = prompt("Please enter your name:", "here");
switch(name.toLowerCase()){
case "paul": id = "Webmaster Paul";
case "jesse": id = "Brother Jesse";
case "luke": id = "Luke...";
}
if(name=="" || name=="here") {
var accept = confirm("Please enter a name");
if(accept==true){location.reload();}
else {self.close();}
}
alert("Hi, "+id);
</script>


[J]ona

Paul Jr
11-18-2003, 12:58 PM
Problem: The ID's are not working. If you enter in any of the specified names (Luke, Paul, Jesse), it just displays, "Hi, luke..." and if you enter in anything else, it just says, "Hi, " without even displaying the name...:confused:

Jona
11-18-2003, 03:28 PM
Add break; after each case: statement. (case "paul": id = "Webaster Paul"; break; for example.)

[J]ona

Paul Jr
11-18-2003, 05:41 PM
Ah, sweet, works like a charm. Thanks!

Jona
11-18-2003, 08:17 PM
Need the break; statement to be explained?

[J]ona