limit no of char per line

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

limit no of char per line

 
0
  #1
Dec 1st, 2008
hi
i have a text area where i want to limit the number of charactersin each line.
for example if the user enters more than 50 caharacters it should automatically move the cursor to the next line
thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: limit no of char per line

 
0
  #2
Dec 1st, 2008
I do not know if there is a simple way. But at this moment here what you can do.

Write a event handler for onkeyup for your text area and count for every keypress if count exceeds 50 then append '\n'(new line character) by yourself.

thats it.
Your js keyhandler will look somthing like this:-
  1. var count = 0;
  2. function keypress (e) {
  3. if(count>=50) {
  4. document.getElementById('textarea_id').value = document.getElementById('textarea_id').value + '\n';
  5. count = 0;
  6. } else {
  7. count++;
  8. }
  9. }
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: limit no of char per line

 
0
  #3
Dec 2nd, 2008
this is not working
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: limit no of char per line

 
0
  #4
Dec 2nd, 2008
What have you done till now?
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: limit no of char per line

 
0
  #5
Dec 2nd, 2008
Of course its working man. I tried it with document.getElementById('id of textarea')

What you want? That a working code is delivered to you so that you can sit back and rest.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: limit no of char per line

 
0
  #6
Dec 2nd, 2008
tried something like this
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script language="javascript" type="text/javascript">
  5. <!--
  6. var count = 0;
  7. function ress(){
  8.  
  9. if(count>=5) {
  10. document.getElementById('textarea_id').value = document.getElementById('textarea_id').value + '\n';
  11. count = 0;
  12. } else {
  13. count++;
  14. }
  15. }
  16. //-->
  17. </script>
  18. </head>
  19.  
  20. <body>
  21. <form>
  22. <textarea name="textarea_id" onkeypress="ress();"></textarea>
  23. </form>
  24. </body>
  25. </html>
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: limit no of char per line

 
0
  #7
Dec 2nd, 2008
in the function you have passed a variable called 'e'...wat is tat for
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: limit no of char per line

 
0
  #8
Dec 2nd, 2008
Where you had set the id for textarea?

ignore e in the function
Last edited by Luckychap; Dec 2nd, 2008 at 6:11 am.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: limit no of char per line

 
0
  #9
Dec 3rd, 2008
i want it to work when the tries to paste also
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC