JavaScript
  Home arrow JavaScript arrow Page 7 - Stringing Things Along
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Stringing Things Along
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2003-01-22

    Table of Contents:
  • Stringing Things Along
  • Elementary School
  • When Size Does Matter
  • Slice And Dice
  • Building Character
  • Search And Destroy
  • Bigger, Bolder, Better

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Stringing Things Along - Bigger, Bolder, Better
    (Page 7 of 7 )

    Finally, if you're looking to perform a little cosmetic surgery on your strings, a good place to start is the toLowerCase() method, which comes in handy if you need to convert a string into entirely lower-case characters (there's also a toUpperCase() method, in case you change your mind)

    <script language="JavaScript">
    // set string
    var str = "Jack Frost";
    // returns "jack frost"
    alert(str.toLowerCase());
    // returns "JACK FROST"
    alert(str.toUpperCase());
    </script>


    If you use HTML (I assume you do, otherwise you wouldn't have gotten this far), you'll be happy to hear that JavaScript provides a number of string formatting options equivalent to HTML's formatting tags. These options as exposed as methods of the String object. Here's an example which demonstrates:

    <script language="Javascript">
    // create a String object
    var myStr = new String()
    myStr = "Look, Ma, no hands";
    // write it as is
    document.write(myStr);
    document.write("<br>");
    // make it bolder...
    document.write(myStr.bold());
    document.write("<br>");
    // ...bigger..
    document.write(myStr.big());
    document.write("<br>");
    // ...more violent
    document.write(myStr.strike());
    document.write("<br>");
    </script>


    These methods allow developers to alter text formatting at runtime within the client, rather than with server-side code - this is good for a number of reasons, including the fact that user interface and presentation logic now lie in the domain of the client rather than the server.

    Wanna use all those functions together? Sure!

    <script language="Javascript">
    // create a String object
    var myStr = new String()
    myStr = "Look, Ma, no hands";
    // all at once
    document.write(myStr.bold().big().strike());
    </script>


    JavaScript also comes with a bunch of other methods that allow you to alter the formatting of a string - play with them on your own time and see what they can do:

    blink() - create a blinking string;

    fixed() - create a string with a fixed-width font;

    fontcolor() - set the font colour;

    fontsize() - set the font size;

    sub() - subscript the string;

    sup() - superscript the string;

    And that's about it. I hope you enjoyed this article, and that it offered you some insight into the string processing power at your disposal in JavaScript. Now, get out there and practice!

    Note: All examples in this article have been tested on Internet Explorer 5.5 for Windows 98. Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. YMMV!
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    JAVASCRIPT ARTICLES

    - Getting Attention with Interactive Effects
    - Interacting with Tooltips and Previews
    - Just-in-Time Information and Ajax
    - Interactive Effects
    - Using Cookies With JavaScript
    - Understanding the JavaScript RegExp Object
    - Controlling Browser Properties with JavaScri...
    - Using Timers in JavaScript
    - Form Validation with JavaScript
    - JavaScript Exception Handling
    - Stringing Things Along
    - Understanding The JavaScript Event Model (pa...
    - Understanding The JavaScript Event Model (pa...
    - An Object Lesson In JavaScript

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway