Lesson 7: Confirm boxes:
The confirm box is very similiar to the alert box. It is another built in function so all you have to do is call it. You can call it by typing: confirm("text you want in the box"). And of cours you will most likely need a function to call it. Lets look at an exanmple:
First lets make a very simple function:
function confirmbox() {
confirm("Do you want to go back to the Javascrippt guide?")
}
Next let's make a simple button to call our function from:
<form>
<input type="button" value="Process code" onClick="confirmbox()">
</form>
Now just put insert the function inside the script tags in the header of your template and put the form right after the body tag and save the file and open it in your browser and you will get a button on the page and when you push it the confirm box will pop up! Try it and see.
Now lets do something a bit more interactive using the confirm method. lets say you want to make a script that asks the user if they want to go to yahoo.com to search for something and if they click on {ok} then it will take them to the yahoo search engine and if they close the box, it will go back to the page they were on. lets code it:
First we need a simple web page
<html>
<head>
<title>Confirm Yahoo</title>
</head>
<body>
Okay here is your example page. now imagine we are taking about something
terribly complicated and you come to a place on your page where you do not
feel like explaining something to your target audience and instead of
leaving them high and dry you give them the option of looking it up somewhere
else! So, you may do a little something like this:
<p>
<h2>For more information on this topic, please push the following button:</h2><p>
<form>
<input type="button" value="push to find out more" onclick="confirmIt()">
</form>
</body>
</html>
Now our function:
<script type="text/javascript">
function confirmIt() {
if (confirm("To get more info. from Yahoo hit ok. To go back to current page click cancel."))
{
alert ("Ok...taking you to yahoo search so you can find further information.");
window.open('http://www.yahoo.com/')
}
else
{
alert ("Cancelled....returning to current page.")
}
}
</script>
Okay that will do it. Now copy the function and paste it right after the </title> tag. Now save it as somthing.html and open it with your browser and presto! You have solved the problem. Now I know we have introduced some code here that has not yet been explained. Not to worry! We will go on to explain all of these in more detail beginning in lesson 9. First we want to introduce our 3rd important pop up window function, the Prompt() function.
Javascript Discussion
- - Google Chrome / Mozilla?
- - Delete text after focus c
- - Statistics
- - Tabs using javascript
- - Select all values in te
Javascript Source Code
- - E-mail Validation
- - Required Fields
- - Alert User Depending On Browser
- - All Details About Browser
- - More Browser Detection





