| Author | Post |
|---|
benji Member
| Joined: | Sun Feb 4th, 2007 |
| Location: | |
| Posts: | 7 |
|
Posted: Tue Feb 27th, 2007 05:17 am |
|
Hey Keith,
Just wondering if it is possible to limit the number of characters in the EditBlock to avoid messing up the table/cell layout? I do not recall any documentation or anything in the forum addressing this. Is it possible?
My table and cells are really tight and need to limit the amount of text the user is able to enter into to avoid screwing up everything
Thanks, Benji
|
Keith Moderator
| Joined: | Fri Apr 8th, 2005 |
| Location: | |
| Posts: | 583 |
|
Posted: Tue Feb 27th, 2007 05:04 pm |
|
The only way to do this would be to have special javascript code for the editblock. For example, give the block an id, lets's call it id=cell1, then an an onkeyup event like so:
<DIV id=cell1 onkeyup=check(this.id) editblock="1"></DIV><!-- editblock="1" -->
function check(eb){
chars=document.getElementById(eb).innerHTML
lenArray=chars.split("");
if(lenArray.length>10){
document.getElementById(eb).innerHTML=maxChars
}else{
maxChars=chars
}
}
That would set the maxlength to 10 characters. Of course you'll have to hard code that it, but it will work.
|
benji Member
| Joined: | Sun Feb 4th, 2007 |
| Location: | |
| Posts: | 7 |
|
Posted: Wed Aug 8th, 2007 01:34 am |
|
thanks keith,
i had another question that you may be able to shed some light on. Using this javascript to limit the number of characters works ok, however, it also includes the <html> tags in the character count. Is there anyway to exclude the tags and anything in between from the character count.
thanks benji
|
Keith Moderator
| Joined: | Fri Apr 8th, 2005 |
| Location: | |
| Posts: | 583 |
|
Posted: Wed Aug 8th, 2007 01:46 am |
|
Try this instead.
function check(eb){
chars=document.getElementById(eb).innerText
lenArray=chars.split("");
if(lenArray.length>10){
document.getElementById(eb).innerHTML=maxChars
}else{
maxChars=document.getElementById(eb).innerHTML
}
}
innerText just counts the text content and omits HTML tags.
|
benji Member
| Joined: | Sun Feb 4th, 2007 |
| Location: | |
| Posts: | 7 |
|
Posted: Sun Jan 20th, 2008 12:51 am |
|
Hey Keith,
Thanks for the help with this. I do have one problem/glitch that you may be able to help with.
The javascript code you posted works great; except when the user enters exactly the number of characters allocated (ie: 10, as in the example you gave).
If you save the page after you entered exacly 10 characters, the function does not work correctly, it will let you add any number of characters. However, if it is less than 10 characters, it works like a charm.
Is there something you may be able to add to the function to make it work even when the users enter exactly the max Characters. I am not a javascript guru so my skills are lacking, but even if it was an annoying alert message that would help somewhat.
Thanks again,
Benji
Addendum:
i get the following error:
maxChars is not defined when the page is saved or loaded with exactly 10 characters in the editblock
Last edited on Sat Jan 26th, 2008 06:55 pm by benji |
 Current time is 05:25 pm | |
|