Programming in JavaScript

In this chapter, we'll build our JavaScript foundation by getting the syntax of the language down. For example, you can make decisions based on your data values with the JavaScript if statement. In this code, I'm comparing the value 143 to 719 ; and if 719 is greater than 143 , displaying the message The first value is greater than the second .:

Listing ch06_03.html
 <HTML>     <HEAD>         <TITLE>             Using the JavaScript if Statement         </TITLE>     </HEAD>     <BODY>         <CENTER>             <H1>                 Using the JavaScript if Statement             </H1>         </CENTER>         <SCRIPT LANGUAGE="JavaScript">  if(719 > 143){   document.writeln(   "The first value is greater than the second."   )   }  </SCRIPT>     </BODY> </HTML> 

You can see this Web page at work in Figure 6-3. As indicated in that page, 719 is indeed greater than 143 .

Figure 6-3. Using the JavaScript if Statement in Internet Explorer.

graphics/06fig03.gif

Testing for Errors in Your Code

While you are developing your JavaScript code, Internet Explorer displays an error icon at the lower left (in the status bar) that you can double-click to open a dialog box indicating what errors are in your code. However, Netscape Navigator simply refuses to run that code. To see what the trouble is, just type " javascript: " in the Location box and press Enter. Netscape Navigator opens a new window telling you what's wrong with the code. In Netscape Navigator 6, select the Tasks, Tools, JavaScript Console menu item.

We're going to see statements like the if statement in the remainder of this chapterand we'll put them to work in the next two chapters.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net