Maxlength of the textarea

Dear all

I have a script written by thirdies which would need a little upgrade. Using this script I need give to the user the option to Cancel
and to OK.

At the present time the button "OK" just advice the user that limit of characters was exceed, but I need to have 2 options: CANCEL (break) and OK (go ahead)


<script language="JavaScript">
function maxlength(element, maxvalue)
     {
     var q = eval("document.url."+element+".value.length");
     var r = q - maxvalue;
     var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. If you exceed the application "+
       "character limit, your text will be cut off at least "+r+" characters";
     if (q > maxvalue) alert(msg);
	 
     }
  
</script>

Open in new window



Thanks in advance

BOB
BOB KUSPEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Flabio GatesCommented:
You can use the confirm function instead of alert:
if (q > maxvalue) 
{
    var r = confirm(msg);
    if (r == true) 
    {
        alert("You pressed OK!");        // do what you want here
    } 
    else 
    {
        alert("You pressed Cancel!");    // ditto
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BOB KUSPEAuthor Commented:
Thanks.
0
BOB KUSPEAuthor Commented:
Hi Flabio,

Clicking Ok or canceling, the result is the same, it opens the next screen.

Thanks
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Flabio GatesCommented:
What do you have in your if...else... block?
How are you calling your maxlength function?
0
BOB KUSPEAuthor Commented:
I have this:

This code was placed on asp page : ADD0.ASP

<script language="JavaScript">
function maxlength(element, maxvalue)
     {
     var q = eval("document.url."+element+".value.length");
     var r = q - maxvalue;
     var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. If you exceed the application "+
       "character limit, your text will be cut off at least "+r+" characters";
   //  if (q > maxvalue) alert(msg);
	 if (q > maxvalue) 
{
    var r = confirm(msg);
    if (r == true) 
    {
        alert("You pressed OK");        // do what you want here
    } 
    else 
    {
        alert("You pressed CANCEL");    // ditto
    }
}
     }

  
</script>

Open in new window


If the user clicks on "OK" another page will open: add.asp

If click on CANCEL it must stay on ADD0.ASP
0
Flabio GatesCommented:
You were supposed to change the alerts in my sample code to whatever you wanted the code to do.
The alerts were just placeholders.
0
BOB KUSPEAuthor Commented:
You are right. I need to find "how to do this" in JS. But your code will help me in anyway
0
Flabio GatesCommented:
Here's some JSFiddle demonstrating how to conditionally cancel a submit.
(demo uses JQuery but can be done without it.)
0
BOB KUSPEAuthor Commented:
Very, very good!

Many thanks for your efforts to help me. I am very grateful.

Bob
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.