Web Analytics Made Easy -
StatCounter validation for textarea created at runtime - CodingForum

Announcement

Collapse
No announcement yet.

validation for textarea created at runtime

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • validation for textarea created at runtime

    hi
    i am using asp.net and in that i have a table in that table i have few textarea which are created in runtime according to the requirement.I want to test that the user should not be allowed to enter more than 1000 words in that text area how can i write a validation for that pls help...

  • #2
    http://www.codingforum.net/showthrea...&threadid=6476
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      but the textboxes are created at run time

      thanks for the instant reply but i am using asp.net server controls
      and the textboxes are created dynamically so how shoulod i call the javascript function from the server side

      Comment


      • #4
        I would personally stick with the power of .NET to validate your forms fields. You can not use the JavaScript on server side, if that is what you are saying by your last post. JavaScript can be turned off and your server side can not.

        But if you want to validate it then you just need to write out a line that would call the function

        Response.Write("<script>CallFunction()</script>")

        Or you can add an attribute tag to your form elements with an onload tag so it will validate it that way.

        Go with .NET validatrion, it is very easy withposting back info.

        Eric
        Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

        Comment


        • #5
          any clues

          i could do it by using on the server side
          myTextBox.Attributes.Add("onkeypress", "JavaScript:chkValue(this.value)")

          but still there is proble as if i copy paste my text then the validation is not fired..

          any clues

          Comment


          • #6
            there is "onchange" that validates the code after it has been entered.

            The flaw is the method that you are using to validate.
            Onkeypress will not catch the data entered so you need to have another way to check.

            And if the user turns off JavaScript then the form will not be validaed anyway......

            Eric
            Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

            Comment


            • #7
              so what is the prefered method can u pls send me some lines of code
              thanks

              Comment


              • #8
                Aside from validating in the client-side, validate also in the server-side. Validation on the server-side should ALWAYS be performed even if there is a client-side validation (as Javascript can be turned off).
                Glenn
                vBulletin Mods That Rock!

                Comment


                • #9
                  Hi can u pls write some code so that if the user pastes more than 1000 character then it should be trucated and only 1st thousant should be pasted

                  Comment


                  • #10
                    The last post in the link I posted already provided the code for trapping excess characters entered via copy-paste operation. This is done in the onblur event handler.

                    onblur="maxtext(this, 1000)"
                    Glenn
                    vBulletin Mods That Rock!

                    Comment


                    • #11
                      no on blur does not work
                      this is what i have written on server side to call clien side function
                      myTextBox.Attributes.Add("onblur", "JavaScript:chkValue(this.value)")

                      this is what i have written on client side

                      function chkValue(a)
                      {


                      if (a.length > 100)
                      {
                      a.value = a.substring(0, 100);
                      }

                      }

                      Comment


                      • #12
                        your code is the one that doesn't work. You are passing the string content of the textarea and you expect the "a.value" line to set new value to the field where "a" is the string not the field object. In the first place, "a.value" is not correct as String object has no value property.

                        To solve the problem, pass the object itself.

                        myTextBox.Attributes.Add("onblur", "javascript&#58;chkValue(this)")
                        Code:
                        function chkValue(obj)
                        {
                           if (obj.value.length > 100) 
                          {
                             obj.value = obj.value.substring(0, 100);
                          }
                        }
                        Glenn
                        vBulletin Mods That Rock!

                        Comment


                        • #13
                          thanks glenngv it worked

                          Comment

                          Working...
                          X