gtrufitt Posted March 13, 2008 Share Posted March 13, 2008 Hi, this script is meant to make sure a user cannot enter more than 42 characters into a textarea, but it is not working, any help as to why would be great! <script language="JavaScript" type="text/javascript"> <!-- function maxlength(element, maxvalue) var q = eval("document.pooh."+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. Please abbreviate "+ "your text by at least "+r+" characters"; if (q > maxvalue) alert(msg); //--> </script> <p> <label for name="about">About: </label> <textarea cols="30" rows="5" name="about" maxsize="42" onchange="maxlength('about', 42)">I don't want anyone to know about me!</textarea> </p> Thanks, Gareth Quote Link to comment Share on other sites More sharing options...
fenway Posted March 13, 2008 Share Posted March 13, 2008 Seriously? var q = eval("document.pooh."+element+".value.length"); eval() is evil. var q = document.pooh[element].value.length; And since it's in a form, you should be able to navigate the hierarchy from the form object, no need to go back to document, just takes longer. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.