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

Prompts
















               Prompts are a way to get information from a user:


                           < h t m l >
                           < h e a d >
                              < t i t l e > W e l c o m e < / t i t l e >
                           < / h e a d >
                           < s c r i p t >
                           < ! - -  / / H i d e
                           f u n c t i o n  h e l l o ( ) {
                              v a r  y N a m e = p r o m p t ( " P l e a s e  e n t e r  y o u r  n a m e " ) ;
                              v a r  n u m O n e = p r o m p t ( " E n t e r  a  N u m b e r " ) ;
                              v a r  n u m T w o = p r o m p t ( " E n t e r  a n o t h e r  N u m b e r " ) ;
                              v a r  p r o d u c t N u m s  =  n u m O n e  *  n u m T w o ;
                              v a r  s u m N u m  =  p a r s e F l o a t ( n u m O n e )  +
                           P a r s e F l o a t ( n u m T w o ) ;
                              a l e r t ( " W e l c o m e  "  +  y N a m e  + " !  T h e  p r o d u c t  o f  "  +
                           n u m O n e  +  " a n d  "  +  n u m T w o  +  "  i s :  "  +  p r o d u c t N u m s  +
                           " ,  a n d  t h e  s u m  o f  t h o s e  n u m b e r s  i s :  "  +  s u m N u m ) ;
                           }
                           / / U n h i d e
                           - - >
                           < / s c r i p t >
                           < b o d y  o n L o a d = ” h e l l o ( ) ” >
                           H e l l o
                           < / b o d y >
                           < / h t m l >
               As you can see, we prompted the user for three variables: y N a m e , n u m O n e , and n u m T w o .
               We then used an alert box to output the product of those numbers to the user.


               C o n f i r m s












               A confirm box displays a message of your choice to the user and gives them the option of
               confirming true or false (actually the display is ‘OK’ or ‘Cancel’).   Within your JavaScript




               LoudOffice.com Guide to HTML – Part II                                               Page 27
   22   23   24   25   26   27   28   29   30   31   32