Home arrow JavaScript arrow Page 3 - Some Simple JavaScript Functions
JAVASCRIPT

Some Simple JavaScript Functions


JavaScript can be one of the most useful additions to any web page. In this article, Annette shows us five quick 'n' easy ways that we can use JavaScript to add a touch of functionality to our web pages.

Author Info:
By: Annette Tennison
Rating: 4 stars4 stars4 stars4 stars4 stars / 30
January 31, 2002
TABLE OF CONTENTS:
  1. · Some Simple JavaScript Functions
  2. · JavaScript functions
  3. · JavaScript functions (contd.)
  4. · Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Some Simple JavaScript Functions - JavaScript functions (contd.)
(Page 3 of 4 )

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 the prompt funciton to enter my name

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. Here's the results in my browser:

Using the alert function to display a 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";

Here's how it looked in my browser:

The changed title in my web browser

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.
blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials