Maxlength of the textarea

BOB KUSPE
BOB KUSPE used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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

Author

Commented:
Thanks.

Author

Commented:
Hi Flabio,

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

Thanks
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

What do you have in your if...else... block?
How are you calling your maxlength function?

Author

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
You were supposed to change the alerts in my sample code to whatever you wanted the code to do.
The alerts were just placeholders.

Author

Commented:
You are right. I need to find "how to do this" in JS. But your code will help me in anyway
Here's some JSFiddle demonstrating how to conditionally cancel a submit.
(demo uses JQuery but can be done without it.)

Author

Commented:
Very, very good!

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

Bob

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial