Featured Links

Other Topics
Sponsored Links





Quote of the Day

"They are ill discoverers that think there is no land, when they can see nothing but sea."

Francis Bacon








 




 
Featured Javascript Articles

How To Set Up Your Own Website
This article deals solely with the mechanics of writing a websiteand placing it in the search engines.For an explanation of why you want to do this, and how todetermine what your target audience is, send a blank email towebsitenewsletter@sendfree.com. ...

Seo'S Relationship With Website Architecture
Search engine optimization for today's search engine robots requires that sites be well-designed and easy-to-navigate. To a great degree, organic search engine optimization is simply an extension of best practices in web page design. SEO's relationship ...

Shopping Cart Usability
Shopping Cart UsabilityUsable Shopping Carts Increase SalesE-commerce has been around since 1993 under many different names, but one thing remains constant; shoppers want usable web sites. Without a usable shopping cart the sites typically fail from poor ...




Some Useful JavaScript Tricks
 
JavaScript can be one of the most useful additions to any web
page. It comes bundled with Microsoft Internet Explorer and
Netscape Navigator and it allows us to perform field validations,
mouse-overs images, open popup windows, and a slew of other
things.

In this article I will show you how to:

- Display the browser name and version number
- Change the text in the status bar of the browser
- Use an input box to get text from the user
- Use a message box to display text to the user
- Change the title of the browser window

Before that, however, we need to know how to setup our web page
so that it can run the JavaScript. JavaScript code is inserted
between opening and closing script tags: tags. When you load the
page in your browser, the JavaScript code will be executed
automatically.

-----------------------------------------------
Displaying the browsers name and version number
-----------------------------------------------

The "navigator" object in JavaScript contains the details of the
users browser, including its name and version number. We can
display them in our browser using the document.write function:

document.write("Your browser is: " + navigator.appName);
document.write("
Its version is: " + navigator.appVersion);

I run Windows 2000 and Internet Explorer version 6, so the output
from the code above looks like this in my browser window:

Your browser is: Microsoft Internet Explorer
Its version is: 4.0 (compatible; MSIE 6.0b; Windows NT 5.0)

-----------------------------------------------
Changing the text in the status bar of the browser
-----------------------------------------------

To change the text in the status bar of a browser window, we just
change the "status" member of the "window" object, which
represents our entire browser window:

window.status = "This is some text";

-----------------------------------------------
Using an input box to get text from the user
-----------------------------------------------

Just like in traditional windows applications, we can use an
input box to get some text input from the user. The "prompt"
function is all we need:

var name = prompt("What is your name?");
document.write("Hello " + name);

The prompt function accepts just one argument (the title of the
input box), and returns the value entered into the text box. In
the example above, we get the users name and store it in the
"name" variable. We then use the "document.write" function to
output their name into the browser window.

-----------------------------------------------
Using a message box to display text to the user
-----------------------------------------------

We can display a message box containing an OK button. These
are great when you want to let the user know what is happening
during their time on a particular page. We can use a message box
to display the "name" variable from our previous example:

var name = prompt("What is your name?");
alert("Your name is: " + name);

The "alert" function takes one argument, which is the text to
display inside of the message box.

-----------------------------------------------
Changing the title of the browser window
-----------------------------------------------

To change the title of our web browser's window, we simply modify
the "document.title" variable, like this:

document.title = "My new title";

One bad thing about the "document.title" variable is that we can
only manipulate it in Microsoft Internet Explorer. Netscape's
implementation of JavaScript doesn't allow us to modify it.

-----------------------------------------------
In Closing
-----------------------------------------------

As you can see from the examples in this article, JavaScript is a
powerful scripting language that we can use to enhance our
visitors experience with our site. You shouldn't use JavaScript
too much, however, because in some cases it can annoy your
visitors and send them packing before your site even loads!

About the Author
Mitchell Harper is the founder of http://www.devarticles.com.
DevArticles provides its visitors with useful, informative
articles on ASP, PHP, and .NET, as well as heaps of tips and
tricks that you wont find anywhere else! To see what it's all
about, visit devArticles right now at http://www.devarticles.com



Javascript News


Financial Times

What Gaza means for people in the UK
BBC News, UK - 8 hours ago
Please turn on JavaScript. Media requires JavaScript to play. The recent attack by Israeli planes close to a UN school in Gaza, which left more than 30 dead ...
Video: Gaza families mourn dead after UN school bombed - 07 Jan 09 AlJazeeraEnglish
What's going on in Gaza? Radio 1
Can Egypt broker truce in Gaza once again? Christian Science Monitor
BBC News - BBC News
all 28,543 news articles

ABC News

An extensive look at Apple's new iWork.com service
Apple Insider, VA - 3 hours ago
Google's WebKit-based Chrome browser and its V8 JavaScript engine are part of that strategy. While Apple is also working along the same lines, ...
Video: Steve Jobs Weight Loss Due to Hormone Imbalance AssociatedPress
Apple's Life After Steve Jobs Slashdot
Live Coverage of the Macworld Expo Keynote Address by Phil ... The Mac Observer
all 2,681 news articles

Calgary Herald

Newsticker requires javascript
Peace fm Online, Ghana - 17 hours ago
The US on Tuesday congratulated Professor John Evans Atta Mills on his victory in the Presidential race. “We commend the Ghanaian people on their resolve ...
Newsticker requires javascript Peace fm Online
Newsticker requires javascript Peace fm Online
Newsticker requires javascript Peace fm Online
Peace fm Online - Peace fm Online
all 865 news articles

Newsticker requires javascript
Peace fm Online, Ghana - 7 hours ago
The 5th Parliament of the 4th Republic today unanimously elected Mrs. Justice Joyce Bamford-Addo a retired Supreme Court Judge as the Speaker of the House ...

Voice of America

Newsticker requires javascript
Peace fm Online, Ghana - 13 hours ago
Heads of private sector associations have begun preaching to the incoming government headed by Professor John Evans Atta Mills to put the economy first, ...
Newsticker requires javascript Peace fm Online
Newsticker requires javascript Peace fm Online
Newsticker requires javascript Peace fm Online
Peace fm Online - Peace fm Online
all 76 news articles