Results 1 to 10 of 10

Thread: add a * after every 60 characters

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513

    Question add a * after every 60 characters

    I have a scrolling text box and after every 60 characters I want to add a * ... How can I do this using javascript

  2. #2
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Define "scrolling text box".

    Is the user entering data or is the data already in the box?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    wohoo, first post after a long holiday in Spain.

    get all the text which is scrolling into a variable called text_which_scrolls

    then try this untested code:
    Code:
    new_text=""
    j=0
    for (i=60; i<text_which_scrolls.length; i=i+60)
      {
      new_text += text_which_scrolls.substring(j,i)+"*"
      j=i
      }
    text_which_scrolls = new_text

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513
    a scrolling text box is a text box with scroll bars...

    <textarea rows="2" name="S1" cols="20"></textarea>

  5. #5
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    I've done it but I'm not hapyy with it, it only works in IE and I don't know why. Can some one please tell me why?
    Here's the code:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    function doIt() {
    text_which_scrolls = document.getElementById('wee').innerHTML
    new_text=""
    i= new Number(0)
    while (i<text_which_scrolls.length)
    	{
    	new_text += text_which_scrolls.substring(i,parseInt(i)+60)+"*"
    	i=i+60
    	}
    alert(new_text)
    document.getElementById('wee').innerHTML = new_text
    }
    </script>
    </head>
    
    <body onload="doIt()">
    <textarea cols="20" rows="10" id="wee">
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    </textarea>
    </body>
    </html>

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513
    This is good. As I asked the * is placed at the end of the 60th character. This may cut off a letter in a word. Is it possible to put a * at the end of the last word before 60 characters?

  7. #7
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    you do want it to insert a character right? not replace the 60th char with a *.

    I could make it reaplce the nearest space which is behind every 60th char. Is that ok?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513
    That would be perfect..

  9. #9
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    sorry but I don't have time to write this, maybe someone else can. Basically you need to get the substring of the 60 char chunk. then do a lastIndexOf(" ") of it, then replace that with a *. not hard. I just don't have time.
    Have I helped you? Please Rate my posts.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Use the value property to refer to the contents of the text area.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width