htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 2: htmlArea 2 & 3 archive (read only): htmlArea v2.0:
max length in textarea? javascript functions collide ?


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


frank7l7
Novice

Jul 8, 2003, 7:39 AM

Post #1 of 25 (7141 views)
Shortcut
max length in textarea? javascript functions collide ? Can't Post

hi there,

iam a new user and htmlarea is very handy - one little problem is to set the max length in a textarea. i search the forum and i found some nice things to check the length before the form is send. there is just one problem i cant get it to run with htmlarea i guess this is just a minor thing since i dont have hardly any clue about javascript. it seems that the functions or something collide? here is the message and the script:

The JavaScript at the following url will limit the number of
characters in a TextArea:
http://webdeveloper.earthweb.com/webjs/item/0,,12744_101541,00.html
(works with IE only)

Here is the code:


Code
   

<SCRIPT Language = "JavaScript">
<!--

function doleft2() {
document.form.text.value = "";
}

function docheck() {
char = eval(document.form.text.value.length)
var dif = eval(char - 125)
var value = document.form.text.value.substr(0,char-dif);
document.form.text.value = value;
var left = "0"
}

function doleft() {
total = eval("125")
char = eval(document.form.text.value.length)
left = eval(total - char)
if (left <= "-1")
{
var dif = eval(char - 125)
var value = document.form.text.value.substr(0,char-dif);
document.form.text.value = value;
var left = "0"
}
document.form.left.value = left
}


document.write("<body OnLoad=\"doleft2()\">")


-->
</SCRIPT>
<CENTER>
<FORM NAME="form" onsubmit="docheck();alert('This javascript will not send. It is just a sample.')">
<TEXTAREA onclick="docheck()" onkeyup="javascript:doleft();" id="text" name="text" Rows="6" Cols="24"></TEXTAREA></TEXTAREA><BR><BR>You have <INPUT Type="Text" Name="left" value="125" Size="3" readonly id="left"></INPUT> characters left.<BR><BR><INPUT Type="submit" Name="" Value="Send!"></INPUT> &nbsp <input type="reset" value="Clear"><BR><BR>
</FORM>---- now if i want to insert the htmlarea editor generator line after the textarea i dont get a errormsg but the counter doesnt work whats wrong?i really appreciate any help


Luis
Veteran

Jul 8, 2003, 11:31 AM

Post #2 of 25 (7134 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Hi Frank717:

Try putting your counter in editor.js. The link below could help you:

http://www.interactivetools.com/forum/gforum.cgi?post=12215


Don't give up!!
http://webstationone.com/test/htmlarea


frank7l7
Novice

Jul 8, 2003, 2:14 PM

Post #3 of 25 (7119 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

hello & thanks for the reply -> i tried the modifications but its the bug with the html character count;( i need it to count the visible chars. i also tried th kb counter but that didnt work. honestly im not to good or lets say i hardly know javascript:( hm, maybe you or somebody knows a simple way to limit the visible chars the user can type - i think this would be very handy for everyone dont you?

im very appreciate your help - and yes html area is wondertool i love it - thanks so much

fra7l7


Luis
Veteran

Jul 8, 2003, 2:32 PM

Post #4 of 25 (7116 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Yes it's very handy. With the example in the mentioned page

You can count:
  • Characters including HTML tags.
  • Visible Characters only.
  • Visible Words
  • Estimated File Size


Unfortunatelly the code there is a little messy. I'll post a clean example for you later tonight.

The only really concerning bug for me is that this workaround kills the undo/redo functionality, that's why I disabled it from my test editor.

Greetings


Don't give up!!
http://webstationone.com/test/htmlarea


(This post was edited by Luis on Jul 8, 2003, 2:33 PM)


Luis
Veteran

Jul 8, 2003, 11:00 PM

Post #5 of 25 (7102 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Hi Frank 717:

Here is the original workaround by Benjamin, with an improvement I did to avoid counting HTML tags.

All changes are in lines 396-403 in
function editor_event(objname,runDelay)

Then, put this line in yor page where the textarea is:

Keystrokes: <INPUT TYPE="text" NAME="counter" SIZE="2" STYLE="background-color: buttonface; border: none; color:red" VALUE="0">

in line 401 of editor.js you can configure the allowed max. chars:
var max_chars = 125;

Once the textarea content has reached the max. chars, all keys in the keyboard will be cancelled but the backspace, in order to allow the user to finish the paragraph correctly.


Don't give up!!
http://webstationone.com/test/htmlarea


(This post was edited by Luis on Jul 8, 2003, 11:01 PM)
Attachments: editor_counter.js (46.4 KB)


frank7l7
Novice

Jul 9, 2003, 3:33 AM

Post #6 of 25 (7092 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

thank you that is indeed simply solid working and perfectly fits the needs

thx


frank7l7
Novice

Jul 18, 2003, 10:56 AM

Post #7 of 25 (7006 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

hi luis,

remember this thread? i have a little problem with your modification when using more then one textareas because the var max_chars is global. i tried to modify the script so the variable can by changed from the html site where the textareas are embedded (var config = new Object(); .... ) but that doesnt work of course because im just to lame coding javascript. maybe it is possible to have individual counters where the max length could be a variable? ofcourse possible for you:)

thanks, ... looking forward to your reply



frank7l7


Luis
Veteran

Jul 18, 2003, 12:01 PM

Post #8 of 25 (7002 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Hi Frank717:

I don't have my files here. My guess is that it should be possible from editor.js.

Including the counters in the .html area page won't work (I think), unless you update the counter manually with an event call, which is not a solution because it won't be aware of when to stop until the script runs.

Could you post your files so I can take a look later tonight and try to find out something?


Don't give up!!
http://webstationone.com/test/htmlarea


frank7l7
Novice

Jul 18, 2003, 1:51 PM

Post #9 of 25 (6996 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

i kind of figured that this would be not so ez. i have zipped my whole htmlarea modification .. i dont know maybe you just need the editor.js and the index but anyway there you have the whole package. im only two steps away (well actual you guys helping me out) to have the perfect cms solution thanks to you.

nr. 1 this max char problem and
nr. 2 im still trying to figure out a insert link for internal links from a dropdown list

well soon ....

thanks so much Blush
Attachments: html area.zip (218 KB)


Luis
Veteran

Jul 19, 2003, 5:22 PM

Post #10 of 25 (6970 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Hi frank717:

Here it is!!

Notice that the name of the textareas are hard-typed in editor.js. You will need to fix it everytime you change the name of a textarea or use allways the same names. You can keep adding as much counting routines as textareas you have.

I noticed a bug in the mod, which is that it doesn't prevent of pasting contents larger than the limit. I'll try to make something for this later next week.


Don't give up!!
http://webstationone.com/test/htmlarea
Attachments: frank_counter.zip (25.5 KB)


frank7l7
Novice

Jul 21, 2003, 10:07 AM

Post #11 of 25 (6934 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

thanks so much its work just perfect:) about the copy & paste problem ... hmm if it is possible to modify me and a lot others will be really thankfull. in any case it is also possible to check max length with a single javascript when the user clicks the submit button.

anyway thx so much for your neverending support Smile


frank7l7
Novice

Jul 23, 2003, 6:00 AM

Post #12 of 25 (6852 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

hi luis,

i bet you real busy?
i tried to insert a seperat javascript to validate forms in case the user copys and pasts more chars then the max_length but somehow these dont work? (i guess its some code conflict with editor.js or something) anyway it wont work ,.... hm did you find anything out yet? i mean only if you can spare a little time :)

thxs so much

frank7l7


frank7l7
Novice

Aug 7, 2003, 4:04 AM

Post #13 of 25 (6699 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

hello luis,

remember me? a little time went down the stream and i wonder if you could hlep me still with this prob?
its still the copy and paste problem ... could you take a look into it once more?

i will try to fix it own me own neverless even thou i dont have a clue about js but the max length is a must for my purpose ...

thanks in advance

frank7l7


Luis
Veteran

Aug 7, 2003, 11:31 AM

Post #14 of 25 (6689 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Hi frank717:
Regarding the scripts being broken, Yes, I realized this problem last week. I made a modification to the Word cleaner and Paste functions. I'll send them later tonight. I'm at work now.

Regarding the counter when pasting, I've not been able to make it work as I would like. I'm trying the function trims the pasted text to exactly the maxlength, but for the way as evrything is inter-related, I've had not success. The most I've achieved, is to trim it up to some un-determined number of characters less than the maxlength. Let's say, if your max length is i.e. 500, the pasted content will be trimmed to something below 500 (440, 445 or who knows how many chars. It's because the function cannot know how many chars belong to HTML and I've not found a way to do it).

I think this is an advance. You could have an alert message saying for example:

"The content you pasted exceeds the number of characters allowed. Your text has been trimmed, leaving X characters free to allow you finishing your paragraph properly"

What do you thing? Will this work for you?


Don't give up!!
http://webstationone.com/test/htmlarea


(This post was edited by Luis on Aug 7, 2003, 12:15 PM)


frank7l7
Novice

Aug 8, 2003, 1:46 AM

Post #15 of 25 (6661 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

that would be perfect:) a thougt about the word cleaner prob also wenn inserting a doc with more chars .... but it looks like you have a perfect solution there im very happy to see it work

thanks so much luis Blush

frank7l7


Luis
Veteran

Aug 8, 2003, 2:45 AM

Post #16 of 25 (6655 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Ok frank, I'll work on it next weekend.

Just remind me something. The maxlength is with html included or only text?


Don't give up!!
http://webstationone.com/test/htmlarea


(This post was edited by Luis on Aug 8, 2003, 2:58 AM)


frank7l7
Novice

Aug 8, 2003, 6:42 AM

Post #17 of 25 (6644 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

max lenth was only text you already fixed it (see previous posts)

thanks next week is perfect ...



frank7l7


frank7l7
Novice

Aug 20, 2003, 5:40 AM

Post #18 of 25 (6525 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

hi luis,



dont wanna bug you but did you have success on the modification yet? Unsure

thxs

frank7l7


Luis
Veteran

Aug 20, 2003, 1:08 PM

Post #19 of 25 (6510 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Hi Frank717:

No success on this. I could only achieve something close removing all formatting from pasted text. Once the text is pasted, it can be reformatted without any problem. What dou you think?


Don't give up!!
http://webstationone.com/test/htmlarea


frank7l7
Novice

Aug 20, 2003, 2:07 PM

Post #20 of 25 (6501 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

that would be alright to limit max length is more important:)

its not perfect but hey what more can i ask for htmlarea did so much for my projekt yet Smile



thx frank7l7


Demonhunter
New User

Aug 21, 2003, 4:31 AM

Post #21 of 25 (6477 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

This is how I solved the problem. The idea is to cut everything more than max_chars before denying acces to all other key than DEL (as shown by Luis!).
I've tested it and it worked well for my needs... just edit editor.js as shown:

function editor_event(objname,runDelay) {
//**COUNTER-CODE**//
var max_chars = 250;
var contents = editor_getHTML(objname);
contents = contents.replace(/<(.+?)>/g, '');//Don't count HTML tags
contents = contents.replace(/&nbsp;/g, ' ');//Count &nbsp; as one keystroke
var count=contents.length;
// document.all['counter_chars'].value = count;
if(count > max_chars) {
editor_setHTML(objname,contents.substr(0,max_chars));
rest = 0;
} else { rest = max_chars - count; }
if (rest >= 0) { document.all['counter'].value=rest; }
//**COUNTER-CODE**//


var config = document.all[objname].config;

... and later on ...

if (editEvent && editEvent.keyCode) {
//**COUNTER-CODE**//
if (rest <= 0 && editEvent.keyCode != 8) { editEvent.returnValue = false; return; }
//**COUNTER-CODE**//

var ord = editEvent.keyCode; // ascii order of key pressed



Hope it will help

Michele


Luis
Veteran

Aug 25, 2003, 1:25 AM

Post #22 of 25 (6416 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Hi frank7l7:

I'm sorry for the delay. Here it is.

Maybe it's similar to what demonHunter suggest, anyway I attach it here so you have two different options to choice the one that fits your needs better.

Bads: Once the text is trimmed, the user can format it again. However, everytime the max chars allowed is reached, all formatting is lost again. Maybe you want to put some alert to advise the user.

Greetings.


Don't give up!!
http://webstationone.com/test/htmlarea
Attachments: editor.js (103 KB)


frank7l7
Novice

Nov 1, 2003, 7:09 AM

Post #23 of 25 (5632 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

hi luis,

i was out of work for a longer period, now as i trying to come back and insert the code for the mod in your last post i forget where the lines are you modificated in the editor.js. second question how was it implemented in the html page again. i had a folder on my comp with my expirments but cant find it anymoreUnsure
we had a hidden input box which showed the char length ...

damn i cant remember .... please if you could post the html file too



thanks so much



fra7l7


Luis
Veteran

Nov 4, 2003, 1:05 AM

Post #24 of 25 (5565 views)
Shortcut
Re: [frank7l7] max length in textarea? javascript functions collide ? [In reply to] Can't Post

Hi Frank:

I have made some improvements to the script. Do you remember we had to declare one function for each textarea in editor.js? Ok, now You don't need to mess with editor.js anymore.

Instead, you have to change a little bit the textboxes in your .html page.
Example: If your textarea's name is Body, add Body_ as prefix to the name of your textbox counter.
<input type="text" name="Body_countchars" id="200">

If you have another textarea called -let's say- Content, make it
<input type="text" name="Content_countchars" id="500">

The Id of the textbox indicates the max. chars allowed in the corresponding textarea. I'm attaching the files here. Anyway, if you have more questions don't hesitate to contact me again.

Greetings


Don't give up!!
http://webstationone.com/test/htmlarea
Attachments: editor_counter.js (103 KB)
  example.html (2.07 KB)


frank7l7
Novice

Nov 4, 2003, 6:03 AM

Post #25 of 25 (5558 views)
Shortcut
Re: [Luis] max length in textarea? javascript functions collide ? [In reply to] Can't Post

oh this is so nice and eazy working .. thanks so much i would suggest to make a announcment for this add on because i believe a lot of people might be interested!

anyway thanks so much ... i have one task left and then everything works fine with htmlarea.

this is what i call great and excellent support



thanx



fra7l7

 
 
 


Search for (options)