Posted: Sat Mar 22, 2008 12:46 pm Post subject: Confirm and Prompt popups
Before you read through this tutorial, make sure you know some parts from the alert-tutorial.
Confirm
The Confirm popup is just a popup-message with a OK and Cancel buttong. The text on your website for a visiter depends on which of these two buttons s/he presses.
Instead of using "function message()", you have to use "function disp_confirm()".
Start by writing the basic HTML-tags pluss the basic Confirm popup-tags:
Now, when you're done writing this, you have to use the 'var', 'if' and 'else' tags.
After writing "var", write a random letter. This random letter is going to make the "if"-tag work. after writing the random letter, write "=confirm("Your message")". Now, write "if" below the line, then write "("The-random-letter-you-picked-earlier==true")". Just to make a long, geeky tutorial short, write what's shown under this sentence between the "{" and the "}":
Code:
var h=confirm("This is a very, very, VERY exciting message. Now, click OK or Cancel.")
if (h==true)
{
document.write("LOLOLOLOLOLOL you pressed OK.")
}
else
{
document.write("Oh noes. :'(")
}
And the final result is:
Code:
<html>
<head>
<title>Whatsoever</title>
<script type="text/javascript">
function disp_confirm()
{
var h=confirm("This is a very, very, VERY exciting message. Now, click OK or Cancel.")
if (h==true)
{
document.write("LOLOLOLOLOLOL you pressed OK.")
}
else
{
document.write("Oh noes. :'(")
}
}
</script>
<body>
<body onLoad="disp_confirm">
</body>
</html>
Aaaaand you're done! Unlike the Alert popup, Confirm popups can't be displayed after each other.
Prompt
Pretty much the same as the Confirm popup, but this time the popup won't decide how the whole page is going to look like, just a small part.
Again, start by writing the basics, but this time with "function disp_prompt()":
Again, you have to use the "var" and the "if" tag, but not the "else" tag. If you want to, you can write "var asdfgh=prompt("Blablabla.","Blablabla")" if you want this to automaticly get written into the line without doing anything to the rest of the popup or you website.
When you're done writing this, write "document.write("The answer on the last question is: "+the-random-letter(s)+". Am I smart or am I smart?")
Do like it's shown under:
Code:
function disp_prompt()
{
var abc=prompt("Just type in your friggin favorite food.","Hamburger")
if (abc!=null&&abc!="")
{
document.write("Your favorite food is "+abc+"! HAH!!")
}
}
And the final result is:
Code:
<html>
<head>
<title>Whatsoever</title>
<script type="text/javascript">
function disp_prompt()
{
var abc=prompt("Just type in your friggin favorite food.","Hamburger")
if (abc!=null&&abc!="")
{
document.write("Your favorite food is "+abc+"! HAH!!")
}
}
</script>
<body>
<body onLoad="disp_prompt()">
</body>
</html>
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum