Sometimes you need to tell a user something and make sure the user sees it. That's when you use an alert box.
Other times you need to make a user either confirm or decline something.That's when you could use a confirm box. Along with confirm boxes you could create a function to reply to what the user clicks on a comfirm box.That will be discribed at the end.
For an alert box we simply use this:
Now to make that show up anywhere we create a functionCode:alert("Here is the alert")
and a buttonCode:function alert() { alert("Here is my alert") }
So our full code isCode:<button type="button" onclick="alert()">Show Alert</button>
Code:<head><script type="text/javascript"> function alert() { alert("Here is my alert") } </script></head><body><button type="button" onclick="alert()">Show Alert!</button></body>
For a confirm box.
Inside the head we do just about the same thing:
and in the body tag:Code:function confirm() { confirm("Are you serious?") }
Using ifCode:<button type="button" onclick="confirm()">Confirm this!</button>
Let's say you wanted something where if someone clicks yes, they get an alert that says something else. Do this with:
Did you single click or double click?Code:<head><script type="text/javascript"> function cnfrm() { confirm("Are you serious?") if(r==true) { alert("Wow you are serious") }} </script></head><body><button type="button" onclick="cnfrm()">Confirm!</button></body>
Here we can create an alert that tells if you clicked once or twice:
This is my second tutorial, Enjoy!Code:<head><script type="text/javascript"> function click() { alert("You clicked once") } function dblclick() { alert("You clicked twice") } </script> </head><body><button type="button" onclick="click()" ondblclick="dblclick()">Click 1 or 2 times</button></body>
Last edited by toxifyshadow; 03-30-2010 at 03:52 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks