Pages

Thursday, 27 March 2014

HTML SPACIAL TAGS



HTML Special Tags
HTML - Body
As we mentioned, the <body> tag serves as the element containing all the content for the website. Tables, lists, forms, paragraphs, and everything else must be placed within the body element to ensure each element is displayed on your site.

HTML - Body Margins

Unique Attributes
  • leftmargin - Sets a left hand margin for your body element.
  • topmargin - Sets a margin along the top of your body element.
A unique set of margin attributes are available to the body tag. These attributes work much like those of a word processing program, allowing you set pixel value margins for the left, right, top, or bottom of your website. Setting these attributes means that all the content you place within your body tags will honor the preset margin.

HTML Code:

<body topmargin="50">
<body leftmargin="50">

Margin Example-1:

Top Margin

Margin Example-2:

Left Margin

HTML - Base Text

The text attribute sets the text color of all text contained within the body tags. Think of it as a means to set the color of your text, unless otherwise noted. Basically, you use these tags to set a base color scheme, which you can later modify through additional tags inside of the body.

HTML Code:

<body text="red" >
or
 
<body text="rgb(255,0,0)" >

HTML - Base Links

Along the same lines, we may also specify base colors for visited or unvisited links. This method has deprecated, and we recommend that you use Cascading Style Sheets (CSS) instead.

HTML Code:

<body link="white" vlink="black" >



or
 
<body link="rgb(255,255,255)" vlink="rgb(0,0,0)" >
Setting a baselink is a great way to ensure your viewers will not receive the annoying error message that occurs with broken links.

HTML - Music Codes

Inserting music onto a web page is relatively easy these days. In the past, multiple tags had to be used because browsers did not have a uniform standard for embedded media files. However, we're happy to announce that this is a problem of the past, and you will now have a much easier time than webmasters of the past.

HTML - Embed

Music is inserted onto a web page with the use of the embed tag. There are other ways to link to music, but embed is now considered the standard for inserting media. Below is an minimalist example of the embed tag using the src attribute to define the media file's location.

HTML Embed Tag Code:

<embed src="beethoven.mid" />



<p>Above is an embedded media player.  To stop the music press stop/pause.</p>
Depending on what kind of media software you or your visitor has installed, the above example will appear slightly different. To make your embedded player display properly, change the attributes associated with display.

HTML - Embed Attributes - Related to Display

To customize the appearance of the embedded media player, be sure to set the following attributes.
  • width - The width of the media player.
  • height - The height of the media player.
  • hidden - Determines if the media player is visible. If this value is set to "true", the media player will not be displayed. We recommend using this attribute only if you know that your visitors will not want the option to stop the music that is playing on your web page (The values are "true" or "false").

HTML Code:

<embed src="beethoven.mid" width="360" height="165" />

Embedded Music:

Usually, you do not want to mess with the width and height of the media player, as it can cause the media player to look rather distorted.

HTML - Embed Attributes - Related to Functionality

To customize the functionality of the embedded media player, be sure to set the following attributes.
  • autostart - Allows media player to start automaticcaly (values are "true" and "false")
  • loop - Sets whether or not the media file will repeat (values are "true" and "false")
  • volume - Sets the volume of the media file (values range from "0" to "100")

HTML Code:

<embed src="beethoven.mid" autostart="false" loop="false"
volume="60" />

Customize Your Code:

 

HTML - Video Codes

Video files, including YouTube videos, are embedded into an HTML document using the <embed> tag. The src attribute defines what video file to embed into the page. The <embed> tag does not require a closing tag. Here is a look at the <embed> tag with a global URL. Notice that its controls, including Play, Stop, Pause, and volume, are already included.

HTML Code:

<embed src="http://www.your url/files/html/htmlexample.mpeg"
 autostart="false" />

Mpeg Movie:

You may start and stop your movie files by either pressing the buttons at the bottom of the object or by single-clicking on the object itself. The movie can be restarted by double-clicking your mouse.

HTML - Video Media Types

Flash (.swf) and MOV (.mov) file types are also supported by the <embed> tag.
  • .swf - Macromedia's Flash file types - very high compression, great for the web!.
  • .wmv - Microsoft's Window's Media Video file types - good quality, variable compression.
  • .mov - Apple's Quick Time Movie format - good quality, variable compression.
  • .mpeg - the accepted standard for web movie files created by the Moving Pictures Expert Group - good quality, variable compression.
The list above outlines some of the most common "internet-ready" video files. Macromedia's .swf and .mpeg formats may be the best options for use with the web because the high compression rate of these file types reduces file size and expedites the download/buffering periods for your page visitors.
You may also simply place the URL of your media files into the href attribute of an anchor tag, much like the concept of "thumbnailing" images.

HTML Code:

<a href="http://your url/pics/flash/motiontween1easy.swf">
motiontween1easy.swf</a>

HTML - YouTube Videos

YouTube videos can be included in HTML documents, and Google offers the code to do so right on the same page as the video itself!
The code offered by YouTube includes a small handful of parameters that help customize the embedded video object, and if you dive deep enough into the code, you will be able to identify the <embed> element and see the src attribute pointing to the URL of the media file.

YouTube Video Code:

<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/opVb89Cmrtkamp;hl=enamp;fs=1">
  </param><param name="allowFullScreen" value="true">
  </param><param name="allowscriptaccess" value="always"></param>
  <embed src="http://www.youtube.com/v/opVb89Cmrtk&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344">
  </embed>
</object>

Embed YouTube Video:

HTML - Embed Attributes

To customize the functionality of the embedded media player, be sure to set any of the following attributes.
  • autostart - Controls the media's ability to start without prompting (values are "true" or "false")
  • hidden - Controls whether or not the play/stop/pause embedded object is hidden or not (values are "true" or "false"; hide your embeded media if you just want background noise)
  • loop - Controls the ability of the media to continuously play (values are "true" and "false")
  • playcount - Sets a playcount which means the media will repeat itself x number of times, instead of continuously as with the loop attribute above (a playcount of "2" will repeat the video twice)
  • volumn - Sets a numeric value for the loudness of your media (values are "0" through "100")

HTML - Meta Tags and Meta Data

Meta tags are used to supply information for search engines that will not be seen by the web surfer. These invisible units provide a flag for search engines to investigate and will then present that data to any potential users that stumble across your site through a search engine.
In the past, meta tags were the primary means for your site to be recognized by web spiders, but webmasters abused meta tags to improve their rankings in search engines. As a result, search engines have since modified their approach to keep results accurate. They now rely less on meta tags. Nevertheless, you should still include meta for those search bots that still do recognize them.

HTML - Meta Tag Description

Search engines are the compasses of the web and help users navigate from site to site. Chances are, if you've used a search engine, you've probably seen the description meta tag in action.
Meta elements must be placed inside of the <head> element in order for them to be recognizable by web crawlers and bots. The <meta> tag generally requires the name and content attributes to be working together to present your web page in a good light.

HTML Code:

<head>
<meta name="description" content="your contains webmaster tutorials." />
</head>
The description meta element allows the developer to summarize the content that can be found on the page and is often the first chance you'll have to attract visitors. These brief narratives and hooks are often the only opportunity you'll have to generate a lasting first impression.

HTML - Keyword Meta Tags

Keywords and/or phrases may be placed inside the keyword meta element. You should specify the most popular search terms you believe someone would use to reach your website. A few years back, you could spam this meta tag with any and every keyword possible to gain ranking on search engines. Now, however, repeated words, or words that do not pertain to the content of the site, will not benefit your search engine rankings.

HTML Code:

<head>
<meta name="keywords" content="keyword, key keywords, etc" />
</head>
Separate each phrase/word with a comma to create large lists. An example of the keywords meta tag for Tizag.com would go something like this:

HTML Code:

<head>
<meta name="keywords" content="HTML, XHTML, CSS, tutorials, your" />
</head>
Keep in mind that driving traffic and having your site listed high in the search engine rankings is not as easy as placing keywords inside your meta element. The phrase "Search Engine Optimization (SEO)" was coined to describe the rigorous process involved in achieving rankings in search engines. While meta tags do play a small role in this process, they are by no means a one-stop shop for your SEO needs.

HTML - Refresh and Redirect Meta

Later down the road, you may need to redirect traffic to another domain. A common reason might be that you have just purchased a better domain name and would like to retain your old visitors, yet still use your new domain. With the refresh meta tag, you will be able to redirect visitors to the website of your choice or simply refresh your own page to update dynamic content automatically.
For the refresh meta tag, the content attribute accepts two arguments separated by a semicolon (;). The first argument specifies the number of seconds between refreshes or redirection and the 2nd argument is a URL of where the browser will relocate.

HTML Redirect Meta Tag:

<head>
<meta http-equiv="refresh" content="10; url=http://www.your url.com" />
</head>
The above code refreshes Tizag's home page every 10 seconds. A quick refresh may be necessary for news, stocks, or any other time-sensitive information. The most common use for this type of meta tag, however, is redirection. To redirect a viewer automatically, just change the URL to the new site, like shown below. This code will send your visitors to espn.com after landing at your site for five seconds.

HTML Page Refresh Meta Tag:

<head>
<meta http-equiv="refresh" content="5; url=http://www.espn.com" />
</head>

HTML - Revised Meta

The revised meta tag records when the last update was done to the site.

HTML Code:

<head>
<meta name="revised" content="Happy New Year: 1/1/2003" />
</head>

Don't forget to get a little meta with your pages!



HTML - Style Attribute

Understanding the HTML style attribute will provide you with a preview into the Cascading Style Sheet (CSS) world. In fact, the code we'll be using with style is indeed CSS code known as Internal CSS. CSS styling brings a whole new dimension to a website and offers endless customization of HTML elements and web page design.
When the style attribute was introduced into the HTML language along with CSS, a number of HTML attributes and tags became obsolete. Manipulation of the fonts and color of HTML elements is now accomplished through CSS styling, instead of stacking bulky formatting tags one inside the other.

HTML Style: Inline CSS:

<p id="contentParagraph" style="color: #0900C4;">
Here we've changed the font color of this paragraph to blue.
</p>

HTML Styling:

Here we've changed the font color of this paragraph to blue.
In the HTML Font lesson, we achieved similar results, but the code used to do so was cumbersome and inefficient.

HTML - Styling

As we mentioned, the values passed to the style attribute are actually CSS code. This means that we can go ahead and pass a series of values at once, changing several properties in one go. Simply separate each CSS attribute with a semicolon (;).

HTML Font Styling:

<p id="contentParagraph" style="font-family: Georgia ; font-size: 12pt; color: #0900C4;">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

HTML Font Styling:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Inline CSS with the HTML style attribute offers a great way to improve the visual display of web elements and pages. With this new understanding of HTML and CSS, you're well on your way to mastering web design.

HTML - Div Element(s)

The <div> tag is nothing more than a container unit that encapsulates other page elements and divides the HTML document into sections. Web developers use <div> elements to group together HTML elements and apply CSS styles to many elements at once. For instance, by wrapping a set of paragraph elements into a <div> element, the developer can take advantage of CSS styles and apply a font to all paragraphs at once by applying a font style to the <div> tag instead of coding the same style for each paragraph element.
Group together text elements within a <div> tag to slice up HTML documents.

HTML Div Element Code:

<div id="myDiv" name="myDiv" title="Example Div Element">
  <h5>Subtitle</h5>
  <p>This paragraph would be your content paragraph...</p>
  <p>Here's another content article right here.</p>
</div>
With these text elements now grouped together under a <div> element, we can alter the appearance of each underlying element collectively by applying a style attribute to the <div> tag.

HTML Div Element Code:

<div id="myDiv" name="myDiv" title="Example Div Element" style="color: #0900C4; font: Helvetica 12pt;border: 1px solid black;">
  <h5>Subtitle</h5>
  <p>This paragraph would be your content paragraph...</p>
  <p>Here's another content article right here.</p>
</div>

HTML Div Element in Action:

Subtitle
This paragraph would be your content paragraph...
Here's another content article right here.
Elements housed within a <div> tag acquire any styles or properties applied to the master div element. Therefore the paragraph and heading elements should now be rendered blue in a Helvetica font. In addition, we've applied a border to the <div> element just to help visualize the grouping of elements together.

HTML - Div inside of Div

Placing <div> elements inside of other <div> elements allows these elements to be further subdivided.

HTML Div Subdivision:

<div id="myDiv" name="myDiv" title="Example Div Element" style="font-family: Helvetica; font-size: 12pt; border: 1px solid black;">
  <div id="subDiv1" name="subDiv1" title="Subdivision Div Element" style="color: #FF0000; border: 1px dotted black;">
    <h5>Section 1</h5>
    <p>This paragraph would be your content paragraph...</p>
    <p>Here's another content article right here.</p>
  </div>
  <br />
  <div id="subDiv2" name="subDiv2" title="Subdivision Div Element" style="color: #FF00FF;border: 1px dashed black;">
    <h5>Section 2</h5>
    <p>This paragraph would be your content paragraph...</p>
    <p>Here's another content article right here.</p>
  </div>
</div>

Divs Inside of Divs:

Section 1
This paragraph would be your content paragraph...
Here's another content article right here.
Section 2
This paragraph would be your content paragraph...
Here's another content article right here.
This concept is the foundation of which most web pages are now built. HTML documents that are properly divided and subdivided are easy to maintain and modify.

HTML - Page Layouts and Templates

HTML layout is very basic. Not many options exist with the body tag alone. Tables, on the other hand, are the bread and butter of HTML layouts. Any element may be placed inside of a table, including tables themselves!

HTML Code:

<table id="shell" bgcolor="black" border="1" height="200" width="300">
   <tr>
      <td>
         <table id="inner" bgcolor="white" height="100" width="100">
            <tr>
               <td>Tables inside tables!</td>
            </tr>
         </table>
      </td>
   </tr>
</table>

Tables inside tables:

Tables inside tables!
The white table (identified as inner) exists inside of the (shell) table, the black one. A light bulb should be going off inside of your head as you explore how this system will allow for the creation of limitless layouts.

HTML - Standard Layout

A fairly standard layout consists of a banner near the top, navigation, and your content or display box. These are the backbone to any great website.

HTML Code:

<table cellspacing="1" cellpadding="0" border="0"
 bgcolor="black" id="shell" height="250" width="400">
   <tr height="50">
      <td colspan="2" bgcolor="white">
         <table title="Banner" id="banner" border="0">
            <tr><td>Place a banner here</td></tr>
         </table>
      </td>
   </tr>
   <tr height="200">
      <td bgcolor="white">
         <table id="navigation" title="Navigation" border="0">
            <tr><td>Links!</td></tr>
            <tr><td>Links!</td></tr>
            <tr><td>Links!</td></tr>
         </table>
      </td><td bgcolor="white">
         <table title="Content" id="content" border="0">
            <tr><td>Content goes here</td></tr>
         </table>
      </td>
   </tr>
</table>

Basic Layout:

Place a banner here
Links!
Links!
Links!
Content goes here
This approach is basic, yet organized. The code becomes complex rather fast, so you will need to be sure to properly assign height and width values to your tables as well. The more specific you are about heights and widths, the less room there will be for error and debugging.

HTML Code:

<table id="shell" title="Shell" height="250" width="400"
 border="0" bgcolor="black" cellspacing="1" cellpadding="0">
   <tr height="50">
      <td bgcolor="white">
         <table title="banner" id="banner">
            <tr><td>Banner goes here</td></tr>
         </table>
      </td>
   </tr>
   <tr height="25">
      <td bgcolor="white">
         <table title="Navigation" id="navigation">
            <tr><td>Links!</td>
            <td>Links!</td>
            <td>Links!</td></tr>
         </table>
      </td>
   </tr>
   <tr>
      <td bgcolor="white">
         <table title="Content" id="content">
            <tr>
               <td>Content goes here</td>
            </tr>
         </table>
      </td>
   </tr>
</table>

Basic Layout 2:

Banner goes here
Links!
Links!
Links!
Content goes here
The code is quite a lot to look at, SO break it up and organize it in your own way to make things easier for you.
               


HTML - Frames

Frames allow for multiple .html documents to be displayed inside of one browser window at a time. This means that one page has no content on it, but rather tells the browser which web pages you would like to open. With the addition of CSS and PHP, frames have become outdated, but if you wish to use them, read on.

Frames - A Generic Frame Page

Frames are most typically used to have a menu in one frame, and content in another frame. When someone clicks a link on the menu, that link is then opened in the content page. Here is a classic example of a basic "index" frameset with a menu on the left and content on the right.

HTML Code:

<html>
  <body>
    <frameset cols="30%,*">
      <frame src="menu.html">
      <frame src="content.html">
    </frameset>
  </body>
</html>

Frame Set:

Here's the example: Frame Index
  • frameset - The parent tag that defines the characteristics of this frames page. Individual frames are defined inside it.
  • frameset cols="#%, *" - The width that each frame will have. In the above example, we chose the menu (the 1st column) to be 30% of the total page and used a "*", which means the content (the 2nd column) will use the remaining width for itself (70%).
  • frame src="" - The URL of the web page to load into the frame.
A good rule of thumb is to call the page which contains this frame information "index.html", as that is typically a site's main page.

Adding a Banner or Title Frame

Add a row to the top for a title and graphics with the code as follows:

HTML Code:

<html>
  <body>
    <frameset rows="20%,*">
      <frame src="title.html">
      <frameset cols="30%,*">
        <frame src="menu.html">
        <frame src="content.html">
      </frameset>
    </frameset>
  </body>
</html>

FrameBorder and FrameSpacing

You've probably noticed those ugly gray lines that appear between the frames. It is possible to remove these and manipulate the spacing between frames with frameborder and framespacing. These attributes appear within the frameset tag.
Note: Framespacing and border are the same attribute, but some browsers only recognize one or the other, so use both, with the same value, to be safe.
  • frameborder="#" - Determines whether there will be a border.
  • border="#"- Modifies the border width.
  • framespacing="#" -Modifies the border width, used by Internet Explorer.
Here's an example of the same frameset without the borders.

HTML Code:

<html>
  <body>
    <frameset border="0" frameborder="0" framespacing="0" rows="20%,*">
      <frame src="title.html">
      <frameset border="0" frameborder="0" framespacing="0" cols="30%,*">
        <frame src="menu.html">
        <frame src="content.html">
      </frameset>
    </frameset>
  </body>
</html>

Frame Borders:

Here's a visual:

Frame Name and Frame Target

How nice would it be to make each menu link load into the content page? We do this by naming each frame and setting the correct base target inside "menu.html".

HTML Code:

<html>
  <body>
    <frameset rows="20%,*">
      <frame name="title" src="title.html">
      <frameset cols="30%,*">
        <frame name="menu" src="menu.html">
        <name="content" src="content.html">
      </frameset>
    </frameset>
  </body>
</html>

HTML Code:

<html>
  <head>
    <base target="content">
  </head>
  <body>
    <!-- Content Goes Here -->
  </body>
</html>

Frame Target:

Here's the Visual:
We first named the content frame "content" on our frame page, and then we set the base target inside "menu.html" to point to that frame. Our frame page is now a perfectly functional menu and content layout!

Noresize and Scrolling

It's possible to further customize the <frame> tag using the noresize and scrolling attributes.

HTML Code:

<html>
  <body>
    <frameset border="2" frameborder="1" framespacing="2" rows="20%,*">
      <frame src="title.html" noresize scrolling="no">
      <frameset border="4" frameborder="1" framespacing="4" cols="30%,*">
        <frame src="menu.html" scrolling="auto" noresize>
        <frame src="content.html" scrolling="yes" noresize>
      </frameset>
    </frameset>
  </body>
</html>

Noresize and Scrolling:

Here's the Visual:
  • noresize - Determines whether the frames can be resized by the visitor or not. (values "true" and "false")
  • scrolling - Determines whether scrolling is allowed in the frame or not (values "true" and "false")
We set the scrolling for our content frame to "yes" to ensure our visitors will be able to scroll if the content goes off the screen. We also set the scrolling for our title banner to no, because it does not make sense to have a scrollbar appear in the title frame.

HTML Character Entities

An "entity" is a fancy term for a symbol. Several symbols, such as copyright, trademark, or foreign cash symbols, exist on your standard keyboard, so you need to display these characters using a different method.
There are three parts to every entity.
  • Each begins with a ampersand - &
  • Then the entities name - copy
  • And finally a semicolon - ;

Copyright:

Combine &copy; to make - © - Copyright symbol.
Expect complications if you forget to include all three parts of an entity.

More Entities:

¢
Cent
¢
&cent;
£
English Pound
£
&pound;
¤
Currency
¤
&curren;
¥
Yen
¥
&yen;
®
Registered Trademark
®
&reg;
°
Degree(s)
°
&deg;
±
Plus or Minus
±
&plusmn;
¼
¼ Fraction
¼
&frac14;
½
½ Fraction
½
&frac12;
¾
¾ Fraction
¾
&frac34;
View a more complete list at: Entities Table

Additional Spaces and <>.

Regardless of how many spaces you place between words, your web browser will only render a single space. To get around this, use the non-breaking space character entity.

HTML Code:

<p>Everything that goes up, must come &nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp; down!</p>

Spaces:

Everything that goes up, must come       down!
In HTML, we use less than and greater than characters to create tags, so to use them on your website you will need entities.

HTML Code:

<p>
Less than - &lt; <br />
Greater than - &gt; <br />
Body tag - &lt;body&gt;
</p>

Less than Greater than:

Less than - <
Greater than - >
Body tag - <body>
Take a few minutes to view and play with the symbols listed in the Entities Table.

HTML - Scripts

There are two very popular scripting languages that are commonly used in HTML to make web pages come alive. JavaScript and VBScript are very useful scripting languages to know, if you have the time.
With HTML scripts, you can create dynamic web pages, make image rollovers for really cool menu effects, or even validate the data on your HTML forms before users submit their information. However, JavaScript and VBScript are very complicated compared to HTML. It may be simpler just to download someone else's scripting code and modify it for use on your web page (if they have given you permission to do so, of course!).

HTML Javascript Code

If you want to insert JavaScript code into your HTML, you are going to use the <script> tag. If you would like to know more about JavaScript, check out our JavaScript Tutorial. Below is the correct code to insert embedded JavaScript code onto your site.

HTML Code:

<script type="text/javascript">
<!--script
***Some JavaScript code should go here***
-->
</script>
For JavaScript, you set the type attribute equal to "text/javascript", which is similar to the process of specifying CSS. We can also include a comment around the JavaScript code. This will prevent browsers that do not support JavaScript or have had JavaScript disabled from displaying the JavaScript code in the web browser.

HTML VBScript How To

To insert VBScript code onto your website, you must once again make use of the <script> tag. Below is the correct code to insert VBScript code onto your site.

HTML Code:

<script type="text/vbscript">
<!--script
***The VBScript code should go in this spot***
-->
</script>
For VBScript, you set the type attribute equal to "text/vbscript", which is similar to specifying CSS. We also include a comment around the VBScript code. This will prevent browsers that do not support VBScript or have had VBScript disabled from displaying the VBScript code in the web browser.

HTML - <!-- Commenting Scripts -->

Scripting languages such as JavaScript and VBScript must be commented out as well. You will learn that it is only once they are placed within the <script> tags that the browser executes the scripts without causing errors.

HTML Code:

<script>
<!-- 
document.write("Hello World!")
//-->
</script>
With this example, we are jumping far ahead. Just be sure you understand when to use comments and where to look for them. They are a very useful tool for any large HTML project.



Wednesday, 26 March 2014

How Do We Use of HTML Tag's

A web browser reads an HTML document from top to bottom, left to right. Each time the browser finds a tag, the tag is rendered accordingly. Paragraph tags render paragraph text, image tags render images, etc. By adding tags to an HTML document, you are not only coding HTML, but also signaling to the browser, "Hey look, this is paragraph text; now treat it as such!"

Do you recall that HTML elements are comprised of three major parts: the opening tag, the content, and the closing tag? As you will learn, there are infinite combinations of HTML tags/elements, including those used for forms, images, and lists. Everything displayed on an web page requires the use of a tag or two.

HTML Tag Code:

<tag>Content</tag>
<p>This text will be rendered like a paragraph.</p>

Tags should always be written in lowercase letters if you plan on publishing the page online, as this is the web standard for XHTML and Dynamic HTML.

HTML More Tag Code:

<body>Body Tag 
<p>Paragraph Tag</p>
<h2>Heading Tag</h2>
<b>Bold Tag</b>
<i>Italic Tag</i>
</body>

HTML - Elements Without Closing Tags


There are a few elements that do not require formal closing tags. In a way, they still have the 3 parts (opening/closing and content), but they are consolidated into one tag. The reason for this is that these tags do not really require any content to be placed within them, but sometimes may require attributes such as source URLs for images.
One prime, easy example of an HTML tag that does not require a closing tag is the line break tag.

HTML Line Break Code:

<br />
To tell the browser we want to place a line break (carriage return) onto the site, it is not necessary to type <br>linebreak</br>. This would require a tremendous amount of effort,and if every line break tag needed all three components as other tags do, life would become redundant real quick. The better solution is to combine the opening and closing tags into a single format and shorten the number of characters needed to render a line break. Other tags, such as image tags and input tags, have also been modified in such a manner.

HTML Code:

<img src="../mypic.jpg" /> -- Image Tag
<br /> -- Line Break Tag
<input type="text" size="12" /> -- Input Field

Display:

--Line Break--
As you can see from the above, the web browser is capable of interpreting the image tag as long as we inform the browser where the image file is located, using the src attribute. Attributes will be discussed in more detail throughout the remainder of the tutorial. For now, it's a good time to start thinking about what type of website you want to make. It is always easier to make content for a topic or to achieve a goal.

EVERY INTERNET USER PERSON SHOULD KNOW HTML BASIC



I hate seeing text-based links in blog posts, social media and forum threads. I don't want to copy and paste the text into a new tab, I just want it to open the link. Not every site enables auto-linking, so sometimes you have to do it the old-fashioned way. Here's how to create a hyperlink:
Hyperlink Note: Just like everything that goes up must come down, every bracket you open must be closed.
If you've used Microsoft Word, you're probably familiar with the different styles, each varying in importance. Headings in HTML work the same way and can also be important for search engine optimization. An H1 is the most important, H2 slightly less, and so on.
Heading
Add caption






  Paragraphs and Spacing

Paragraphs have about a 1.5 line spacing before and after each block of text. If you don't want the extra spacing, use a break rule.

Paragraph

Images

We all love filling our blog posts and webpages with images, but they don't always fit perfectly in the allocated space. Some basic tags will help you resize images on the fly, although editing images prior to uploading them on your website is preferred so you don't stretch the proportions.
To start, don't upload large image files with a high resolution. Typically 50-150 KB or 150-600 pixels wide will do just fine for most websites. Two optimization tips here -- since search engines can't read images, you need to tell them what the image is -- use keyword-rich file names (inbound-marketing-tips.jpg vs. img01234.jpg) and alternative text (alt text) in case the image doesn't load properly.

Image Image Link

Lists

Finally, there are two basic kinds of lists, ordered and unordered. In other words, numbers or bullets.

Lists
Now go forth and conquer HTML!


Tuesday, 25 March 2014

Know About VB Script Tutorial's How To work

Know About VB Script Tutorial's How To work


VBScript Tutorial
VBScript stands for Visual Basic Script, a scripting language 
developed by Microsoft to be used with Microsoft products,
 mainly Internet Explorer. It has gone through many changes 
over the years and is now mainly used as the default scripting language of ASP.
VBScript: Client Side Scripting
VBScript was created to allow web page developers the ability to c
reate dynamic web pages for their viewers who used Internet
 Explorer. With HTML, not a lot can be done to make a web page
 interactive, but VBScript unlocked many tools like: the ability to 
print the current date and time, access to the web servers file system,
 and allow advanced web programmers to develop web applications.
VBScript: Why Learn and Use It?
VBScript is a prerequisite for ASP developers and should be learned 
thoroughly before attempting any sophisticated ASP programming. 
Programmers who have used Visual Basic in the past will feel more 
at home when designing their dynamic web pages with VBScript, 
but it should be known that only visitor's using Internet Explorer 
will be able to access your code, while other browsers will not 
be able to process the VBScript code.
MYSITE's VBScript Learning: Do's & Don'ts
DO Learn VBScript
  • If you have a solid understanding of HTML
  • If you want to program successfully in ASP
  • If you already know Visual Basic and would like to experiment with VBScript
  • If you are a hobbyist that enjoys knowing many programming
DON'T Learn VBScript
  • If you are developing a web page for the general public
  • If your site has visitors who use a browser other that Internet Explorer
  • If prefer to avoid dying languages. If you want 
  • something more supported, you should learn Javascript
If you still want to learn VBScript then let's get started.
VBScript Installation
VBScript is a client side scripting language that can be developed
 in any text editor. An example of a text editor would be Notepad.
 VBScript is a Microsoft proprietary language that does not
 work outside of Microsoft programs.
VBScript Supported Browsers
After you have written your VBScript code you need to download the
 Internet Explorer to process your code. Firefox, Opera, Netscape, 
etc will not be able to run VBScript. Download Internet Explorer from the Microsoft site.
VBScript Execute Your Scripts
After you have installed Internet Explorer to your computer,
 you can run your VBScript by loading your web page that 
includes your VBScript into Internet Explorer. The
VBScript Debugging
If you would like to enable client side scripting debugging then open up internet explorer and open the Internet Options. Tools < Internet Options. In the options popup window choose the Advanced tab from the tab bar.
Contained here are tens of different options you can manipulate in Internet Explorer. We simply want to turn on debugging for our scripts, so find the Browser section. If you are using Internet Explorer for Windows XP then the option Disable Script Debugging (Internet Explorer) should be the fourth item down in the Browser section.
Uncheck the option Disable Script Debugging (Internet Explorer) and you have now enabled scrip debugging. When you are executing your scripts and they are not functioning properly you can now use the debugger with the menu by going to View < View Debugger < Open. Note: You will need to restart Internet Explorer before this option will show up.
VBScript First Script
We like to teach by example, here at MYSITE.com, so let's start off with a simple VBScript example that will help you get your feet wet. Reminder: We will not be explaining the HTML in this tutorial so review our HTML Tutorial if you ever need extra assistance understanding an example or lesson.
VBScript Script Creation
This first script will be very basic and will write "Hello World" to the browser window, just as if you had typed it in HTML. This may not seem very important, but it will give you a chance to see the VBScript Syntax without getting to complex.


VBScript Code:
<html>
<body>
<script type="text/vbscript">
document.write("Hello World")
</script>
</body>
</html>
Display:
Note: If you are not using Internet Explorer to view this tutorial then you will see nothing displayed. This is because VBScript only runs on Internet Explorer browsers! Just in case you don't have access to Internet Explorer we will be providing a converted output in the rest of our displays for this tutorial.
Display:
Hello World
VBScript <script> Tag
In the above example you saw the basic cookie cutter for inserting a script into a web page. The HTML script tag lets the browser know we are going to use a script and the attribute type specifies which scripting language we are using. VBScript's type is "text/vbscript".
All the VBScript code that you write must be contained within script tags, otherwise they will not function properly.
VBScript Syntax
If you are an expert Visual Basic programmer then you will be pleasantly surprised to know that VBScript has nearly identical syntax to Visual Basic. However, if you are a programmer or only know the basics of HTML then VBScript code may look a little strange to you. This lesson will point out the most important things about VBScript syntax so you can avoid common potholes.
VBScript: No Semicolons!
If you have programmed before, you will be quite accustomed to placing a semicolon at the end of every statement. In VB this is unnecessary because a newline symbolizes the end of the statement. This example will print out 3 separate phrases to the browser. Note: There are 0 semicolons!
VBScript Code:
<script type="text/vbscript">
document.write("No semicolons")
document.write(" were injured in the making")
document.write(" of this tutorial!")
</script>
Display:
No semicolons were injured in the making of this tutorial!
VBScript Accessing Methods
To access methods and properties contained within an object, like the Document object, you use a period "." after the object and before the name of the method.
So far in this tutorial we have been using the write method that is a part of the document object and the syntax for doing this is:
  • document.write(string_here)
VBScript Multiple Line Syntax
As we stated above, the syntax is that placing a newline in your VBScript signifies the end of a statement, much like a semicolon would. However, what happens if your code is so long that absolutely must place your code on multiple lines?
Well, Microsoft has included a special character for these multiple lines of code: the underscore "_". The following example contains an exceptionally long write statement that we will break up string concatenation and the multiple line special character.
VBScript Code:
<script type="text/vbscript">
document.write("This is a very long write " &_
"statement that will need to be placed onto three " &_
"lines to be readable!")
</script>
Display:
This is a very long write statement that will need to be placed onto three lines to be readable!
VBScript Syntax Review
VBScript is a client-side scripting language that is based off of Microsoft's Visual Basic programming language. No semicolons are used at the end of statements, only newlines are used to end a statement.
If you want to access methods of an object then use a period "." and an underscore is used for statements that go multiple lines!
VBScript Variables
Variables in VBScript behave just like those variables you would use in Visual Basic. If you don't know Visual Basic don't worry because we are going to put you through MYSITE's Five Minute VBScript Variable Bootcamp.
For those of you who have not used variables before, then you should know that the notion of variables helps to make programs easier to program and to understand. Variables are used to hold information so that it can be reused throughout the program. You can think of variables as a grocery bag and your information you want to store as your groceries. Without the bag it's going to be a pain the bum to drag all that food around!
Declaring Variables in VBScript
When you are going to use a variable in your VBScript code you should first declare it. To declare a variable in VBScript you use the Visual Basic Dim statement:
VBScript Code:
<script type="text/vbscript">
Dim myVariable1
Dim myVariable2
</script>
Display:
Nothing is displayed because we were simply setting up our variables for use!
Note: It is also possible to declare multiple variables in one line. Use the comma "," to separate your multiple variable names.
VBScript Code:
<script type="text/vbscript">
Dim myVariable1, myVariable2
</script>
Display:
VBScript Variables: Setting Values
When you want to set your variable equal to a value you use the equals character "=", also known as the equals operator. The name of your variable appears on the left of the equals, while the value you are setting your variable equal to appears to the right of the equals.
To use your variable, simply type the variable name where you would like to use it. In this example we create two variables, set set one equal to a number and the other equal to a string. We then use the document.write method to print both out to the browser.
VBScript Code:
<script type="text/vbscript">
Dim myVariable1, myVariable2
myVariable1 = 22
myVariable2 = "Howdy"
document.write("My number is " & myVariable1)
document.write("<br />My string is " & myVariable2)
</script>
Display:
My number is 22 My string is Howdy
VBScript Variables: Setting Objects
Setting Objects? Yes, VBScript allows you to use objects in your code. Objects are blobs of code goo that can contain multiple methods and variable. When you want to use these methods and variables you have to use the period operator "." to gain access to them. See our VBScript Syntax lesson for more information.
When you are setting a value to a variable that is actually an object then you must follow some special syntax. The SET keyword lets VBScript know that you are setting your variable equal to an object. In addition to this, you also have to set the variable equal to nothing after you are finished with it! It's a lot of extra work, but it is necessary.
This example shows how to use a fictional class myClass to create an object. For this example to work you would have to create myClass yourself. Going into more detail is behind the scope of this lesson.
VBScript Code:
<script type="text/vbscript">
Dim myFirstObject
SET myFirstObject = New myClass
myFirstObject = nothing
</script>
Display:
Note: Once again, nothing is displayed because we were just showing you how to set and release an object in VBScript!
VBScript Operators
Operators are used to "do operations" or manipulate variables and values. For example, addition is an example of a mathematical operator and concatenation is an example of a string operator. The plus sign "+" is the operator used in programming language to represent this mathematical addition operation
VBScript's many operators can be separated into four semi-distinct categories:
  • Math Operators
  • Comparison Operators
  • Logic Operators
  • String Concatenation Operator
VBScript Operators: Math
When you want to perform addition, subtraction, multiplication, and other mathematical operations on numbers and variables use the operators listed below.
Operator
English
Example
Result
+
Add
8+7
15
-
Subtract
11-10
1
*
Multiply
7*8
56
/
Divide
8/2
4
^
Exponent
2^4
16
Mod
Modulus
15 Mod 10
5
VBScript Operators: Comparison
When you want to compare two numbers to see which is bigger, if they're equal, or some other type of relationship use the comparison operators listed below. Common uses of comparison operators are within conditional statements like an If Statement or the condition check in a While Loop.







Operator
English
Example
Result
=
Equal To
10 =1 4
False
Greater Than
10 > 14
False
Less Than
10 < 14
True
>=
Greater Than Or Equal To
10 >= 14
False
<=
Less Than Or Equal To
10 <= 14
True
<> 
Not Equal To
10 <> 14
5
VBScript Operators: Logic
Logic operators are used to manipulate and create logical statements. For example if you wanted a variable shoeSize to be equal to 10 or 11 then you would do something like:
VBScript Code:
<script type="text/vbscript">
Dim shoeSize
shoeSize = 10
If shoeSize = 10 Or shoeSize = 12 Then
'Some code
EndIf

</script>
A detailed explanation of Logic and Logic Operators are beyond the scope of this tutorial, but we do have a list of the various logic operators available to you in VBScript.
Operator
English
Example
Result
Not
Inverts Truth Value
Not False
True
Or
Either Can Be True
True Or False
True
And
Both Must Be True
True And False
False


VBScript String Concatenation Operator
When you have various strings that you would like to combine into one string use the concatenation operator. The concatenation operator acts as a glue between the two or more strings you wish to attach, effectively making them into one string. String concatenation is often used when using the document.write function.
Operator
English
Example
Result
&
Connected To
"Hello" & " there"
"Hello there"
Be sure to bookmark this page so that you can use it as a reference if you forget the various operators available in VBScript.
VBScript Strings
Strings are a bunch of alpha-numeric characters grouped together into a "string" of characters. This sentence I am writing right now is an example of a text string and it could be saved to a VBScript string variable if I wanted it to.
VBScript String Syntax
To create a string in VBScript you must surround the letters or numbers you wish to be stringanized (that's a made up MYSITE word) with quotations, like this:
  • "Hello I am a string!"
VBScript String: Saving into Variables
Just like numeric values, strings in VBScript are saved to variables using the equal operator. This example shows how to save the string "Hello there!" into the variable myString and then use that variable with the document.write function.
VBScript Code:
<script type="text/vbscript">
Dim myString
myString = "Hello there!"
document.write(myString)
</script>
Display:
Hello there!

VBScript String Concatenation
Often it is advantageous to combine two or more strings into one. This operation of adding a string to another string is referred to as concatenation. The VBScript script concatenation operator is an ampersand "&" and occurs in between the two strings to be joined. This example will join a total of 4 strings to form a super string. Note: We only use one variable in this example!
VBScript Code:
<script type="text/vbscript">
Dim myString
myString = "Hello there!"
myString = myString & " My name"
myString = myString & " is Frederick"
myString = myString & " Nelson."
document.write(myString)
</script>
Display:
Hello there! My name is Frederick Nelson.
VBScript Arrays
Imagine that you would like to store a list of all the gifts you would like to receive on your wedding day. You want to make a web page that displays a list of all the items. If you were to create a variable for each gift then you might end up having 100 or more variables for gifts alone! However, there is a better solution to this engineering problem.
Instead, you could utilize arrays, which allow you to store many variables(elements) into a super variable (array). Each present would have a position in the array, starting from position 0 and ending with the last gift.
VBScript Creating an Array
We are going to dumb down the example a little bit so that this lesson doesn't get too boring. Let's imagine that we have 4 gifts we want to store in our array. First we need to create an array to store our presents and tell VBScript how big we want our array to be.
As we mentioned, an array's beginning position is 0, so if we specify an array of size 3 that means we can store 4 presents (positions 0, 1, 2 and 3)! This is often confusing for first time VBScript programmers. Below is the correct code to create a VBScript array of size 3.
VBScript Code:
<script type="text/vbscript">
Dim myArray(3)
</script>
VBScript Arrays: Storing Data
Now that we have created our array we can begin storing information into it. The way to do this is similar to setting the value of a variable, but because an array can hold many values you have to specify the position at which you want the value to be saved.
We have four presents that we need to store and we make sure that we don't store two presents in the same position!
VBScript Code:
<script type="text/vbscript">
Dim myArray(3)
myArray(0) = "Clean Underwear"
myArray(1) = "Vacuum Cleaner"
myArray(2) = "New Computer"
myArray(3) = "Talking Bass"
</script>
VBScript Arrays: Accessing Data
We have all the data stored into the array that we need, now we need to figure out how to get it back out so we can print it to the web page! This step is nearly identical to the storing phase because you have to specify the position of the element you wish to display. For example, if we wanted to print out the value of the present at position 0 in our array you would use the following code:
VBScript Code:
<script type="text/vbscript">
Dim myArray(3)
myArray(0) = "Clean Underwear"
myArray(1) = "Vacuum Cleaner"
myArray(2) = "New Computer"
myArray(3) = "Talking Bass"
document.write(myArray(0))
</script>
Display:
Clean Underwear
VBScript Arrays: Accessing All Data
The above example was a good introduction to accessing elements in an array, but it isn't that helpful for printout out all items that might be in an array. If we had 300 items in our array, accessing them one by one would be most time consuming to program.
Below is a piece of code that will automatically go through every element in the array and print it out. The special programming structure this example uses is a For Loop that we will be discussing in greater detail later on in this tutorial.
VBScript Code:
<script type="text/vbscript">
Dim myArray(3)
myArray(0) = "Clean Underwear"
myArray(1) = "Vacuum Cleaner"
myArray(2) = "New Computer"
myArray(3) = "Talking Bass"
For Each present In myArray
document.write(present)
document.write("<br />")
Next
</script>
Display:
Clean Underwear Vacuum Cleaner
New Computer
Talking Bass
VBScript If Statement
One of the most common programming tools that is required to write any kind of program is the If Statement. This lesson will give you the basic rundown of how to implement an If Statement in VBScript.
Making decisions is a tiring process, so it's nice to know that you can make your program make decisions for you if you tell it what it needs to pay attention to. An If Statement is a mechanism programmers have been using for quite some time that will execute a block of code IF conditions are true.
For example, you may want to print out "Is someone having a case of the Mondays?" on your web site every Monday morning. Your If Statement would check to see if the day was a Monday and if it was (true) then it would execute the code to print out that annoying line of text.
VBScript If Statement: Syntax
In this lesson we will be creating a simple VBScript If Statement that checks to see if a number stored in the variable myNumber is equal to 7. If this is true then it will execute a document.write function to print some text to the browser.
VBScript Code:
<script type="text/vbscript">
Dim myNumber
myNumber = 7
If myNumber = 7 Then
        document.write("Lucky 7!")
End If
myNumber = 100343
If myNumber = 7 Then
        document.write("You're a winner!")
End If

</script>
Display:
Lucky 7!
This example show that in our first If Statement myNumber is indeed equal to 7 and the block of code that prints out "Lucky 7!" is executed. However, we then set myNumber equal to something that is not 7 (100343) and check with a second If Statement and the block of code that should print out "You're a winner!" is not executed.
The code that resides within an if statement is only executed if the condition statement of that If Statement is True.
VBScript If Statement: Else
Sometimes you would like to have code executed with something is true and when something is false. For example, if you wanted to wear a T-shirt if the temperature was above 70 and a long-sleeved shirt if it was 70 or less. This action to be taken if the conditional statement is false (that is, the temperature is not above 70 degrees) is referred to in programming speak as the Else clause of the If Statement.
If something is true I want to do Code A, Else I want to do Code B.Below is the implementation of our "what shirt to wear" problem.
VBScript Code:
<script type="text/vbscript">
Dim temperature
temperature = 50
If temperature > 70 Then
        document.write("Wear a T-Shirt!")
Else   
        document.write("Wear a long-sleeved shirt!")
End If


</script>
Display:
Wear a long-sleeved shirt!
VBScript ElseIf
In the previous lesson you learned how to create an If Statement and make use of the Else clause. However, an If Statement is not always enough for a programmer's needs.

VBScript ElseIf: Uses
The previous lesson contained an example that let you execute one block of code if the temperature was above a certain temperature and another block of code if it was below a certain temperature. How would we check for another temperature range? For this kind of programming solution you need to use the ElseIf statement.
The basic idea of the ElseIf statement is to create an If Statement within another If Statement. This way you can check for many different cases in a single If Statement clause.
Our following example shows how you would check for two additional temperature ranges to make our program more robust!
VBScript Code:
<script type="text/vbscript">
Dim temperature
temperature = 65
If temperature > 70 Then
        document.write("Wear a T-Shirt!")
ElseIf  temperature > 60 Then
        document.write("Wear a hat!")
ElseIf  temperature > 50 Then
        document.write("Wear a long-sleeved shirt!")
Else
        document.write("Wear a coat!")
End If

</script>
Display:
Wear a hat!
Our temperature was set to 65 and failed the first If Statement condition because 65 is not greater than 70. However, on the first ElseIf Statement we found that 65 was greater than 60 and so that block of code document.write("Wear a hat!") was executed. Because there was a success the If Statement then finishes and our VBSCript would begin again on the line of code following End If
VBScript Select Case
The last two lessons you have read through have covered the basics of using the If Statement and the somewhat more advanced ElseIf Statement in VBScript. This lesson will take it a step further by teaching you how to implement the Select Case statement in VBScript.
VBScript Select Case: Why Use It?
When you need to check for many different cases on one variable you could create a large number of ElseIf statements, but this is actually very inefficient. Without getting to specific, it takes VBScript a great deal of computing power to check all these different ElseIf statements. Also, this kind of coding reduces human readability. Because of these problems another programming method, the Select Case statement, was created to solve this problem.
The downside to this new method is you can only check if a variable is equal to something "=" and not compare it with greater than, less than, etc (>, <, >=, <=).
VBScript Select Case: Creation
A VBScript Select Case statement can be summed up into three main parts.
  • Variable - The variable contains the value which we are trying to determine. Our example will be a variable containing the name of a person.
  • Case Statements - The case statements contain the values we are checking for. Our example will contain a few names, each their own case statement.
  • Case Code Blocks - Each case statement has a block of code associated with it. When its case statement is True then the block of code is executed. Our example will print out a greeting depending on the person's name.
Below is a simple example of a Select Case statement that will write something different to the web browser depending on the name stored in the variable myName.
VBScript Code:
<script type="text/vbscript">
Dim myName
myName = "Charles"
Select Case myName
Case "Bob"
        document.write("Been busy Bob?")
Case "Sara"
        document.write("Seen any slick sunglasses Sara?")
Case "Charles"
        document.write("Did you chuck your chowder Charles?")
End Select

</script>
Display:
Did you chuck your chowder Charles?




VBScript Select Case: Else Case
Just like an If Statement has an optional Else clause, a Select Statement has an optional Else case. When the variable cannot match any of the cases included then the Else case will be used.
VBScript Code:
<script type="text/vbscript">
Dim myName
myName = "supercalifragilisticexpialidocious"
Select Case myName
Case "Bob"
        document.write("Been busy Bob?")
Case "Sara"
        document.write("Seen any slick sunglasses Sara?")
Case "Charles"
        document.write("Did you chuck your chowder Charles?")
Case Else
        document.write("Who are you?")
End Select
</script>
Display:
Who are you?
VBScript Comments
Comments are used to leave yourself notes or to mark a piece of code so that it doesn't get executed. In VBScript the comment system is extremely simple because there is only one kind of comment.
VBScript Comment: Single Line Comment
VBScript only has support for single line comments, so commenting out large blocks of code or leaving yourself long notes can be quite a bit of work. The apostrophe is the special character VBScript uses as its comment initiator.
The comment in VBScript works by making the VBScript interpreter ignore everything to the right of the apostrophe until a newline is reached. The following example shows how to leave yourself notes and how you would comment out pieces of code you don't want executed.
VBScript Code:
<script type="text/vbscript">
Dim myMessage
'myMessage = "I am having a great day!"
myMessage = "I could use a nap..."

'This will print out myMessage to the visitor
document.write(myMessage)

</script>
Display:
I could use a nap...
Commenting out segments of code is often quite beneficial when you are trying to debug your VBScript code. Leaving yourself notes in your VBScript is also a good programming practice, as it will remind you of the code's purpose months or even years later when you might be reviewing the code for the first time in a long time.
VBScript For Loop
A For Loop is used for special situations when you need to do something over and over again until some condition statement fails. In a previous lesson, VBScript Arrays we used a For Each loop to print out every item in our VBScript array.
The For Loop and the For Each Loop are very useful if you know how to use them. This lesson will teach you the basics of each type of for loop.
VBScript For Loop
VBScript For Loops are a little different compared to conventional for loops you see in programming languages like C++ and Java, so pay extra close attention! The For Loop has a counter variable that is created specifically to keep track of how many times the loop's code has been executed. After each successful execution of the loop VBScript automatically adds 1 to this counter variable and keeps doing this until the MAX is reached.
Here is the pseudo code for a VBScript For Loop:
  • For counterVariable = 0 to MAX
You would replace counterVariable with the name of your counter (most often counter variable used is i). MAX would also be replaced with an integer to specify how many times you would want the For Loop's code executed.
VBScript For Loop Example
To clearly illustrate how a For Loop works in the real world, the following example will print out the counter variable to the browser after each successful loop.
VBScript Code:
<script type="text/vbscript">
For count = 0 to 3
    document.write("<br />Loop #" & count)
Next

</script>
Display:
Loop #0
Loop #1
Loop #2
Loop #3
You can see here that the loop executes 4 times, once for 0, 1, 2 and 3.
VBScript For Each Loop
VBScript For Each Loop is useful when you want to go through every element in an array, but you do not know how many elements there are inside the array.
The following example creates an array and then prints out every element.
VBScript Code:
<script type="text/vbscript">
Dim myCloset(2)
myCloset(0) = "Coat"
myCloset(1) = "Suit"
myCloset(2) = "Boxes"

document.write("In my closet is:")
For Each item In myCloset
    document.write(item & "<br />")
Next
</script>
Display:
In my closet is:Coat
Suit
Boxes
VBScript While Loop
A While Loop is a simple loop that keeps looping while something is true. Everytime it loops the block of code that is contained within the while loop is executed. The while loop is controlled by the same kind of conditional statement that you would see in an VBScript If Statement, so if you already know how an If Statement words, this lesson will be a breeze!
VBScript While Loop Example
In this lesson we will be creating a simple countdown that starts at 10 and ends with a BANG! First, we need to decide what our condition statement will be. Because we are counting down, it only seems logical that we would want our countdown variable to be greater than 0, otherwise we should be having a BANG!
The following code creates the while loop to create a simple VBScript countdown.
VBScript Code:
<script type="text/vbscript">
Dim counter
counter = 10
While counter > 0
    document.write(counter)
    document.write("<br />")
    counter = counter - 1
Wend
document.write("BANG!")
</script>
Display:
10
9
8
7
6
5
4
3
2
1
BANG!
The loop starts with the counter variable equal to 10 and subtracts one from counter each time through the loop. After 10 times(iterations) through the loop the conditional statement counter > 0 fails and the the while loop ends (Wend).
VBScript Functions
When you are programming in VBScript and other languages you may find that you have to program the same code over, and over, and over. This is usually a sign that you should be using a function to reduce this code repetition. Besides that, functions are also useful to increase code readability (when done right).
Nearly all the programs that you write will benefit from functions. Whether you use the pre-made functions like document.write() or make your own it is a necessity for any programmer to have a basic understanding of how functions work in VBScript.
VBScript Function Creation
Let's start off with a really simple example to show the syntax for creating a function. The function myAdd will take two numbers and print out the result.
VBScript Code:
<script type="text/vbscript">
Function myAdd(x,y)
    myAdd = x + y
End Function
'Let's use our function!
Dim result
result = myAdd(10,14)
document.write(result)
</script>
Display:
24
This may not look that complex, but there is actually quite a lot going on this simple example. We first created our function myAdd, which takes two arguments x and y. These two arguments are added together and stored into the myAdd variable.
When our VBScript code executes it first stores the function for later use, then reaches result = myAdd(10,14). VBScript then jumps to the function myAdd with the values x = 10 and y = 14.
Notice that the variable that we store our result in is the same as the function name myAdd. This is on purpose. In VBScript you can only return a value from a function if you store it inside a variable that has the same name as the function.
After the function has completed executing its code the line result = myAdd(10,14) is now result = 24 where result is set equal to the the result of the myAdd function. We then print out the value of result which is 24.
We recommend that you play around with creating VBScript functions for a while to get a better feel for this important programming technique.
VBScript Date Functions
This tutorial will teach you how to use VBScript's Date function and VBScript's Date Format Functions. Both of these functions are included with VBScript. Note: You will need to be running Internet Explorer to see the displays in this tutorial. This is because VBScript is a Microsoft only scripting language.
VBScript Date Function
The VBScript Date function is used to create the current date based off of the visitor's system time. This means that if a user from China and a visitor from America visit your site at the same time they will see their own local time displayed.
This example shows how you would get the current date, store it into a variable and print it to the browser.
VBScript Code:
<script type="text/vbscript">
Dim myDateString
myDateString = Date()
document.write(myDateString)
</script>
Display:
Note: You will only see the Display if you are viewing this web page with Internet Explorer.
VBScript FormatDateTime Function
If the above VBScript Date Format is not to your liking you can use the format constants of the FormatDateTime function to customize your Date display. VBScript has 3 constants that relate to the Date function:
  • 0 - Default setting. You can see this in the example above.
  • 1 - A long date defined by the computer's regional settings.
  • 2 - A short date defined by the regional settings.
We will be formatting the current date with these options, but you can also format static dates (i.e. January 1, 1500) by replacing Date() with your own date string.
VBScript Code:
<script type="text/vbscript">
Dim myDateString0, myDateString1, myDateString2, break
myDateString0 = FormatDateTime(Date(), 0)
myDateString1 = FormatDateTime(Date(), 1)
myDateString2 = FormatDateTime(Date(), 2)

break = "<br />"

document.write(myDateString0 & break)
document.write(myDateString1 & break)
document.write(myDateString2 & break)
</script>
Display:
Note: You will only see the Display if you are viewing this web page with Internet Explorer.

VBScript MsgBox
If you are using Internet Explorer then you would have received a popup as soon as you came to this site. That was a VBScript MsgBox (message box), a popup window that can be called using the MsgBox function. You can use this popup to display crucial information, gather data, or just annoy your visitors!
VBScript MsgBox Creation
To create a simple message box you only need to supply the MsgBox function with a string and this will be what is displayed on the popup prompt. Our following example will popup with the message "Hello There!".
VBScript Code:
<script type="text/vbscript">
MsgBox "Hello There!"
</script>
This is the code for the popup box you see when you load this page.
VBScript MsgBox Arguments
While it is quite easy to create a MsgBox with a simple message, customizing your MsgBox is quote complex. There are up to 4 optional arguments you can give the MsgBox function bringing the grand total to 5 arguments!
However, only two of these options are that useful and they are:
  • Button (Integer)- Allows you to set which buttons will be displayed on your popup. OK button is the default setting.
  • Title (String)- Sets the title of the popup window, much like the HTML title tag sets the title of the browser window.
A complete listing of the button constants can be found at Microsoft's VBScript Reference.
In this example we will be creating a HTML button that creates a MsgBox with a message, a title and an OK and Cancel button when clicked. For a review on HTML Buttons see our

VBScript Code:
<script type="text/vbscript">
Function myPopup_OnClick()
        MsgBox "Hello there!", 1, "Greeting Popup"
End Function
</script>
<form>
<input type="button" value="Click Me!" name="myPopup" />
</form>
Display:
Top of Form
Bottom of Form
CLICK ME