Page 157 - DCAP408_WEB_PROGRAMMING
P. 157

Unit 5: Scripting Language




          In the following example we are using the toUpperCase() method of the String object to display  Notes
          a text in uppercase letters:
                         <script  type=”text/javascript”>
                         var  str=”Hello  world!”;
                         document.write(str.toUpperCase());
                         </script>
          Output

                 HELLO WORLD!
          5.7.1 String Object


          The String object is used to manipulate a stored piece of text.

          Examples of Use

          The following example uses the length property of the String object to find the length of a string:
          var txt=”Hello world!”; document.write(txt.length);
          Output
          12

          The following example uses the toUpperCase() method of the String object to convert a string to
          uppercase letters:
          var txt=”Hello world!”; document.write(txt.toUpperCase());

          The code above will result in the following output:
          HELLO WORLD!


                 Example: Illustrate how to style strings.
                 <html>
                 <body>
                 <script  type=”text/javascript”>
                 var  txt=”Hello  Upendra!”;
                 document.write(“<p>Big:”  +  txt.big()  +  “</p>”);
                 document.write(“<p>Small:”  +  txt.small()  +  “</p>”);
                 document.write(“<p>Bold:”  +  txt.bold()  +  “</p>”);
                 document.write(“<p>Italic:”  +  txt.italics()  +  “</p>”:);
                 document.write(“<p>Blink:”  +  txt.blink()  +  “(does  not  work  in  IE,
                 Chrome,  or  Safari)</       p>”);
                 document.write(“<p>Fixed:”  +  txt.fixed()  +  “</p>”);
                 document.write(“<p>Strike:”  +  txt.strike()  +  “</p>”);
                 document.write(“<p>Fontcolor:”  +  txt.fontcolor(“Red”)  +  “</p>”);
                 document.write(“<p>Fontsize:”  +  txt.fontsize(16)  +  “</p>”);
                 document.write(“<p>Subscript:”  +  txt.sub()  +  “</p>”);
                 document.write(“<p>Superscript:”  +  txt.sup()  +  “</p>”);




                                           LOVELY PROFESSIONAL UNIVERSITY                                   151
   152   153   154   155   156   157   158   159   160   161   162