Page 33 - LoudOffice_Guide-to-HTML_Part-II_Advanced.PDF
P. 33

< / h t m l >
               This will produce a popup window triggered by a button being pressed.




































               Writing HTML with JavaScript
               JavaScript provides two simple methods to write to the HTML document:
                   Ø d o c u m e n t . w r i t e l n ( “ c o n t e n t ” )  – This will write a single line followed by a line
                       break.
                                                           –  This will write text without spacing or line
                   Ø d o c u m e n t . w r i t e ( “ c o n t e n t ” )
                       breaks.

               The following code produces a JavaScript Prompt box that asks for the user’s name and
               then prints out an entire HTML document:


                       < h t m l >
                       < h e a d >
                       < t i t l e > A n o t h e r  J a v a S c r i p t  E x a m p l e < / t i t l e >
                       < / h e a d >
                       < b o d y >
                       < s c r i p t >
                       < ! - -
                       v a r  y o u r N a m e  =  p r o m p t ( " W h a t  i s  y o u r  n a m e ? " ) ;

                       d o c u m e n t . w r i t e l n ( " < h 1 > W e l c o m e  t o  m y  P a g e < / h 1 > " ) ;
                       d o c u m e n t . w r i t e l n ( " < p > T h i s  p a r a g r a p h  i s  w r i t t e n  e n t i r e l y
                       i n  J a v a S c r i p t . < / p > " )
                       d o c u m e n t . w r i t e ( " < p > D o n ' t  y o u  t h i n k  i t ' s  c o o l  " ) ;
                       d o c u m e n t . w r i t e ( y o u r N a m e )
                       d o c u m e n t . w r i t e ( " ? < / p > " )
                       d o c u m e n t . w r i t e l n ( " < p > W i l l  y o u  t r y  i t ? < / p > " ) ;
                       - - >

               LoudOffice.com Guide to HTML – Part II                                               Page 33
   28   29   30   31   32   33   34   35   36   37   38