Learn some hands-on JavaScript
Takeaway: Here's some hands-on JavaScript information and code for beginners.
By Emily A. Vander Veer
Before you dive into JavaScript code, you need to know the tags for embedding JavaScript into your pages.
These are the standard tags to start an HTML page. It's good practice to put the JavaScript code between the <HEAD> and </HEAD> tags so that functions don't get called accidentally before the JavaScript is loaded.
This tells the browser that JavaScript code is about to appear. You may also specify the version of JavaScript in the LANGUAGE attribute, which will cause browsers that do not recognize that version to ignore it. For example, if you specified "LANGUAGE=JavaScript 1.2", any version of Navigator below 4.0 would not process the script.
This is a safety valve. Everything between the <!-- and the --> below will be ignored by browsers that can't interpret JavaScript.
The // is a JavaScript comment indicator that tells the browser's JavaScript interpreter to ignore the following text.
This is where the actual JavaScript goes. The curly braces surround each statement and separate them from other statements in the function. Don't know what a statement is? You will.
These indicate that we're all done with the script and can go back to HTML code.
In this case, we tell the browser to run the JavaScript function someFunction() when the user clicks a button.
That's the end of the page. Everything's ready to run when a user loads the page into a JavaScript-ready browser. Here's a template code that you can cut and paste. Click here.
Emily A. Vander Veer is the author of numerous
Internet-related magazine articles and books, including JavaScript
for Dummies, JavaScript for Dummies Quick Reference, and JavaBeans
for Dummies, all published by IDG Books.
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
// put your JavaScript statements below
function someFunction() {
some JavaScript statements
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<!-- put your HTML statements below -->
<INPUT TYPE="button" NAME="someButton" VALUE="Press Me" onClick="someFunction()">
</FORM>
</BODY>
</HTML>
SponsoredWhite Papers, Webcasts, and Downloads
- VoIP: How to Plan for the Bandwidth and Calculate the Cost Savings Global Knowledge
- Live Webcast: Reduce Your Costs and Prepare for Tomorrow with BMC CONTROL-M BMC Software
- 2007 IT Salary and Skills Survey: What Impacts Salaries? Global Knowledge
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET






