limit textarea issue tinyMCE

im using tinyMCE editor and i want to limit the user to 50 charactors.

if they enter more than this limit, prompt them and ask if they want to enter more.  if yes, show an additional textarea.  

if i enter more than 50 charactors, i get prompted so im happy that my max character check is working.  

however if i try to edit the textarea (e.g. click on the textarea etc etc), i keep getting prompted that im over the max limit and therefore i cannot edit the textarea.

im keeping track of the number of charactors entered into the textarea using this event handler:

handle_event_callback : "CheckSize"

function CheckSize()
{
      var x = tinyMCE.getContent();

      if(x.length > 50)
      {
            if(confirm('You have reached the maximum size for this field.  Do you require to enter more?'))
            {
                  //show extra textarea
            }
            else
            {
            //hide extra textarea
            }
      }
return true;
}
LVL 16
ellandrdAsked:
Who is Participating?
 
BadotzConnect With a Mentor Commented:
So you are imposing the limits of your system's internal workings on your Poor Users? Not very nice.

Why not break the text they enter into 7,000-character chunks when they are done typing? You might have to change your database design to accomodate the user - what a novel concept - because there is no way the user should be made to suffer because of some arbitrary limit of your tools.
0
 
bugs021997Commented:
Are you calling the function CheckSize() on onChange event of the Textarea, if so revert it back to onSubmit of the form....
0
 
BadotzCommented:
Why in the world would you subject your users to this line of reasoning?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ellandrdAuthor Commented:
>>Are you calling the function CheckSize() on onChange event of the Textarea, if so revert it back to onSubmit of the form....

no the textarea has no event trigger attached to it

>>Why in the world would you subject your users to this line of reasoning?

the limit is going to be 7000 - i just have 50 as an example for testing purposes....
0
 
bugs021997Commented:
can you paste your TEXTAREA Code as well as the form tag code
0
 
BadotzCommented:
It is a textarea - why limit the number of characters at all?
0
 
ellandrdAuthor Commented:

<form action="" method="POST">
<textarea name="objective" id="objective"></textarea>
</form>
0
 
ellandrdAuthor Commented:
>>It is a textarea - why limit the number of characters at all?

because the data is going to be saved to ms sql server, where the field type is a varchar of 7000 in length.
0
 
bugs021997Commented:
Try replacing your TEXTAREA with this...

<TEXTAREA onkeyup="this.value = this.value.slice(0, 20)"></TEXTAREA>

Here the number 20 represents allowing only 20 characters, you can increase it to the level you want.....
0
 
bugs021997Connect With a Mentor Commented:
If you don't want to do as posted in my earlier post then use this JAVASCRIPT Function


<SCRIPT LANGUAGE="JAVASCRIPT">
function checkLength(form){
    if (form.description.value.length > 20){
         if(confirm('You have reached the maximum size for this field.  Do you require to enter more?'))
            {
                  //show extra textarea
            }
            else
            {
            //hide extra textarea
            }
    }
    return true;
}
</SCRIPT>

<FORM ACTION="new_page_1.htm" METHOD="post" onSubmit="return checkLength(this)">
<textarea NAME="description">testing by bugs</textarea>
<input type="submit">
</form>
0
 
ellandrdAuthor Commented:
Badotz

it has nothing to do with the design.  in ms sql server database, a varchar field has a limit of 8000 characters - there is nothing i can do to increase this - thats what Microslop set it as.  

i have a form where users can type in a story and im trying to prevent the user from entering too much data.  before trying to limit the user, i had no limit and users entered more than 7000 chars and the characters > 7000 got chopped off with half the story missing.

>>what a novel concept

what a novel solution
0
 
BadotzCommented:
Right - so *after* the Poor User has finished tying, *you* have to break their text into 7,000-character chunks and write *multiple rows* into *your* database. This has noything to do with the limits of SQL Server, it has to do with your (poor) database design.
0
 
ellandrdAuthor Commented:
simple database - 1 table, 2 fields - id (PK auto increment) and story (varchar 7000)

this is my design - what do you suggest then? to allow users write a story and save it in a database instead of mouthing off that my design is poor and im making the user suffer!!  you come up with a better more efficient solution.
0
 
BadotzConnect With a Mentor Commented:
Split the user's input into 7,000 character chunks, and update the database. When requested, re-assemble the chunks into a single textarea.

Just think of yourself on the receiving end of your own restrictions - would you be satisfied with a 7,000 character limit if you needed to type - and save - 7,010 characters? Wouldn't you complain to someone?
0
 
BadotzConnect With a Mentor Commented:
Table: Story
id
text_id
title
author
etc.

Table: Text
id
story_id
text

There is a one-to-many relationship between tables story and text.

0
 
raj3060Commented:
I haven't read everyone's cpmments. My apologies if someone already suggested this.

Try this:

<P>TEXTAREA: <textarea id='TAREA1' name='TAREA' onblur='if(this.value.length>50){alert("You have reached the maximum characters limit.");this.value=this.value.substr(0,50);}'></textarea></P>

You can test the length onsubmit too with validator.
0
 
BadotzCommented:
No worries - glad to help.
0
 
ellandrdAuthor Commented:
thank you raj but you should always read the complete discussion before posting.

Badotz

a bigger thank you goes to you for helping me get a better design.

Ellandrd
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.