PDA

View Full Version : [Tutorial] Writing Alert Boxes and Buttons in JavaScript


xilica
05-23-2002, 10:36 PM
Hey everyone.

note: Before you begin using this tutorial I personally recommend you have a background knowledge in how HTML works. If you don't, you can read my "Into to HTML" tutorial that I wrote for the HTML section.
Also note: If you know about the <HEAD> "tag" this is very important. You must include this piece of code in the <HEAD> "tag" in order to use JavaScript. Here is the code:

<SCRIPT Language ="JavaScript">



Anyway, lets get started!


Adding Alert Boxes

First I will explain how Alert Boxes work. Then I will introduce and explain how to add buttons to your webpage.


This is not a link! (noplace)


This right here is an Alert Link. When you go over the link it pops up an alert. Here is what the code means:

1. onMouseOver="alert(' ')" - This means that when your mouse moves over the link the alert will pop up. That is why the code states "onMouseOver" because on MouseOvering the link the alert pops up.

2. alert(' ') - This is where you type what you want that alert to be. The alert is the box that pops up once you highlight over the link.


Here is how Alerts work if you want the Alert to load before the page loads.


<SCRIPT language ="JavaScript">
<!-- hide from old browsers

alert('Welcome to CoderForums!');

//-->
</SCIRPT>


Here is what the code means:

<!-- hide from old browsers - You put this hear just in case. This is because some older browsers cannot read JavaScript. If they don't read this as JavaScript and it is marked like this then you are fine. It will not display in the webpage because in the code you have stated do not display if it does not work. Note: This code has to be in the <HEAD> "tag."

1. alert(' '); - This is what you put for the text when your Alert Box displays.

2. //--> - This stops hiding the JavaScript from older browsers.

3. </SCRIPT> - Ends the JavaScript commands.

Also in order to add more then one Alert Box all you have to do is this:


alert(' ');
alert(' ');


Basically, the same way you added one except you just add more under one.


Adding Buttons


<FORM>
<INPUT type="button" value="Click here to hear about a good programming Forum!"
onClick="alert('www.CoderForums.net')">
</FORM>


Here is what each piece of the code does:

1. <FORM> - You have to add this in order for the code to run since it is a form.

2. value="" - This is where you type for the value of the button. Basically, what you want the button to say on it.

3. onClick - This states if you click it an alert will appear.


Well that about wraps this tutorial up. If you have any questions feel free to posts them.

Here is a sample program which will sum everything up that you learned through this tutorial:


<HTML>
<HEAD>
<TITLE>JavaScript Tutorial</TITLE>
<SCRIPT language="JavaScript">
alert('Welcome to CoderForums!');
</SCRIPT>
</HEAD>
<BODY>
<FORM>
This is not a link! (noplace)
<INPUT type="button" value="Click here to hear about a good programming Forum!"
onClick="alert('www.CoderForums.net')">
</FORM>
</BODY>
</HTML>

xilica
05-23-2002, 11:11 PM
Here is what the sample code at the bottom of the tutorial looks like at the first Alert Box:

http://www.tmstadium.com/extrastuff/JavaScriptAlerts.jpg


After you highlight the link:

http://www.tmstadium.com/extrastuff/JavaScriptLinks.jpg



When you click the button:

http://www.tmstadium.com/extrastuff/JavaScriptButtons.jpg

hank_freid
04-02-2008, 01:26 AM
First of all i would like to thank the poster who make us educated by giving instruction about alert(''); step by step and in the end ornamented his or here article with beautiful summary of

<HTML>
<HEAD>
<TITLE>JavaScript Tutorial</TITLE>
<SCRIPT language="JavaScript">
alert('Welcome to CoderForums!');
</SCRIPT>
</HEAD>
<BODY>
<FORM>
This is not a link!
<INPUT type="button" value="Click here to hear about a good programming Forum!"
onClick="alert('www.CoderForums.net')">
</FORM>
</BODY>
</HTML>

for more you can read on W3Scools (http://w3schools.com/js)

Olynsky
05-06-2008, 04:09 AM
Great guide.Thanks your very much.
_________________
Link Building Packages (http://www.forumlinkbuilding.com/view.php/link_building_packages)

ShaunDean
08-26-2008, 12:05 AM
Its a kind of educational script you have handed over to us, all the codes are clearly mentioned.Pretty cool i must say, people will learn alot from this.

FreedyGones
09-17-2008, 03:05 AM
First of all i would like to thank the poster who make us educated by giving instruction about alert(''); step by step and in the end ornamented his or here article with beautiful summary of

<HTML>
<HEAD>
<TITLE>JavaScript Tutorial</TITLE>
<SCRIPT language="JavaScript">
alert('Welcome to CoderForums!');
</SCRIPT>
</HEAD>
<BODY>
<FORM>
This is not a link!
<INPUT type="button" value="Click here to hear about a good programming Forum!"
onClick="alert('www.CoderForums.net')">
</FORM>
</BODY>
</HTML>

for more you can read on W3Scools (http://w3schools.com/js)

Really awesome post, i have found the tutorial very informative.As being a Java Script leaner this thing helped me a lot to understand the basics of this language.

Daggwell
12-22-2008, 01:23 PM
I have done a search on the html of the original page, and it has the "Are you sure ..." text but no "OK" anywhere.

The script for FORM_ACTION(0) is:

<INPUT TYPE="SUBMIT" NAME="FORM_ACTION" VALUE="Place Order" onClick=set_submit_type("C")

I suspect the popup uses some kind of standard JavaScript function* that automatically generates "OK" and "Cancel" buttons on the popup. If so, what code do I use
to click the OK button? *I determined later that it is a Confirmation box.

With IE.Document.All
.FORM_ACTION(0).Click
.[need code]

Alex80
01-13-2009, 10:17 AM
It is very informative post, very helpful to go ahead with my web-programming life, Can anyone suggest some reference to get some e-books for javascript?

biophase
01-31-2009, 09:00 PM
I get a page load error on the images.

biophase
01-31-2009, 09:05 PM
Never mind just saw the date on the OP

joewunsch
02-18-2009, 03:27 AM
Is this tutorial broken? I can not get it to load. Can anyone post an updated version?

Florida Lady
04-04-2009, 06:09 PM
Well, that is a very nice sample to start with. Well, I already book mark the HTML tutorial you posted previously. I am going to bookmark again or save this site, so I have something to use and start it with when I am ready to start learning HTML. Thanks

Harrish Ivan
04-08-2009, 10:35 AM
I have learned Javascript & HTML when I was in the 1st year of my IT degree. I had remembered Javascript but I am not much into that. However, now I have joined to a company as a Web designer, So, JavaScript is very important for me....:p, When I have searched some tips for Javascript, I have got this forum, It seems really great.... Can I get some ideas about VBScript too over here in this forum? Let me check :)

mayo
04-14-2009, 09:03 AM
It is great buddy, thanks for the share, I want to know on how to include videos in a page by using Javascript, Do you have any references?

fazthegreat
04-23-2009, 11:18 AM
Harrish if you are interested in learning more javascript. I always go to devguru.com Check it out!

harika123
05-05-2009, 03:04 AM
Hey everyone.

note: Before you begin using this tutorial I personally recommend you have a background knowledge in how HTML works. If you don't, you can read my "Into to HTML" tutorial that I wrote for the HTML section.
Also note: If you know about the <HEAD> "tag" this is very important. You must include this piece of code in the <HEAD> "tag" in order to use JavaScript. Here is the code:

<SCRIPT Language ="JavaScript">



Anyway, lets get started!


Adding Alert Boxes

First I will explain how Alert Boxes work. Then I will introduce and explain how to add buttons to your webpage.


This is not a link! (noplace)


This right here is an Alert Link. When you go over the link it pops up an alert. Here is what the code means:

1. onMouseOver="alert(' ')" - This means that when your mouse moves over the link the alert will pop up. That is why the code states "onMouseOver" because on MouseOvering the link the alert pops up.

2. alert(' ') - This is where you type what you want that alert to be. The alert is the box that pops up once you highlight over the link.


Here is how Alerts work if you want the Alert to load before the page loads.


<SCRIPT language ="JavaScript">
<!-- hide from old browsers

alert('Welcome to CoderForums!');

//-->
</SCIRPT>


Here is what the code means:

<!-- hide from old browsers - You put this hear just in case. This is because some older browsers cannot read JavaScript. If they don't read this as JavaScript and it is marked like this then you are fine. It will not display in the webpage because in the code you have stated do not display if it does not work. Note: This code has to be in the <HEAD> "tag."

1. alert(' '); - This is what you put for the text when your Alert Box displays.

2. //--> - This stops hiding the JavaScript from older browsers.

3. </SCRIPT> - Ends the JavaScript commands.

Also in order to add more then one Alert Box all you have to do is this:


alert(' ');
alert(' ');


Basically, the same way you added one except you just add more under one.


Adding Buttons


<FORM>
<INPUT type="button" value="Click here to hear about a good programming Forum!"
onClick="alert('www.CoderForums.net')">
</FORM>


Here is what each piece of the code does:

1. <FORM> - You have to add this in order for the code to run since it is a form.

2. value="" - This is where you type for the value of the button. Basically, what you want the button to say on it.

3. onClick - This states if you click it an alert will appear.


Well that about wraps this tutorial up. If you have any questions feel free to posts them.

Here is a sample program which will sum everything up that you learned through this tutorial:


<HTML>
<HEAD>
<TITLE>JavaScript Tutorial</TITLE>
<SCRIPT language="JavaScript">
alert('Welcome to CoderForums!');
</SCRIPT>
</HEAD>
<BODY>
<FORM>
This is not a link! (noplace)
<INPUT type="button" value="Click here to hear about a good programming Forum!"
onClick="alert('www.CoderForums.net')">
</FORM>
</BODY>
</HTML>


thank you very much for informative post ... can anyone please explain how to create iframes ?