SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member bishop gideon's Avatar
    Join Date
    Jun 2004
    Location
    aurora
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace() function

    I'm trying somethign new with some javascript and I can't really get it to work the way I want it to. Here's my code:

    Code:
    var x = 0;
    var strText = opener.document.addclass.Description.value;
    var tempLen = strText.length;
    //document.writeln("length="+strText.length);
    while (x <= tempLen)
    {
    	var description = strText.replace(String.fromCharCode(10), "<br>" );
    	var description2 = description.replace(String.fromCharCode(13), "<br>" );				
    	x = x+1;
    }
    document.writeln(description2);
    It's only catching the first instance of (10) and/or (13)... anyone see where I went wrong, and/or an easier way to do this...

    Thanks.
    ----------------------
    Bishop Gideon
    DigitalFreeze.net | ILMRA | MowerRacer.com

  2. #2
    SitePoint Member bishop gideon's Avatar
    Join Date
    Jun 2004
    Location
    aurora
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nevermind... I figured it out...
    ----------------------
    Bishop Gideon
    DigitalFreeze.net | ILMRA | MowerRacer.com

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    replace has a global parameter.

    Code javascript:
    var description = opener.document.addclass.Description.value;
    description = description.replace(String.fromCharCode(10), "<br>", 'g');
    description = description.replace(String.fromCharCode(13), "<br>", 'g');
    document.writeln(description);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •