|
-
Jun 16th, 2004, 02:08 PM
#1
Thread Starter
Fanatic Member
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
-
Jun 16th, 2004, 02:19 PM
#2
Frenzied Member
Define "scrolling text box".
Is the user entering data or is the data already in the box?
-
Jun 16th, 2004, 04:55 PM
#3
Frenzied Member
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
-
Jun 16th, 2004, 06:47 PM
#4
Thread Starter
Fanatic Member
a scrolling text box is a text box with scroll bars...
<textarea rows="2" name="S1" cols="20"></textarea>
-
Jun 16th, 2004, 09:02 PM
#5
Frenzied Member
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>
-
Jun 17th, 2004, 06:52 PM
#6
Thread Starter
Fanatic Member
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?
-
Jun 17th, 2004, 07:24 PM
#7
Frenzied Member
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?
-
Jun 17th, 2004, 07:55 PM
#8
Thread Starter
Fanatic Member
-
Jun 18th, 2004, 09:01 AM
#9
Frenzied Member
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. 
-
Jun 18th, 2004, 10:47 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|