Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. How to use Jquery on a Dynamical created Textbox

How to use Jquery on a Dynamical created Textbox

Scheduled Pinned Locked Moved JavaScript
csharptutorialquestionjavascript
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    Good Day All i am creating Textboxes at Runtime with something like this

    Dim cnt As New TextBox

        cnt.ID = "cont\_" & x
    
        If multiline Then
            cnt.TextMode = TextBoxMode.MultiLine
    
    
        End If
    

    These are dynamically created fields. so what i want to do is to use this following JQuery on this textbox

    $(document).ready(function()
    {
    $("#contentbox").keyup(function()
    {
    var box=$(this).val();
    var main = box.length *100;
    var value= (main / 145);
    var count= 145 - box.length;

        if(box.length <= 145)
        {
        $('#count').html(count);
        $('#bar').animate({"width": value+'%',}, 1);
        }
        return false;
        });
    

    });

    and what this function does it count the number of Characters that have been typed in a Textbox. so i am displaying the remaining characters. So that is working fine on my example because the Element is known at Early Binding. Now my question is what if the textbox is created dynamically ?

    contentbox

    this is the name of the Textbox in my example. hOW do we use a J Query in Dynamically created Textbox. Thanks

    Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@dotnetfunda.com http://www.Dotnetfunda.com

    A A 2 Replies Last reply
    0
    • V Vimalsoft Pty Ltd

      Good Day All i am creating Textboxes at Runtime with something like this

      Dim cnt As New TextBox

          cnt.ID = "cont\_" & x
      
          If multiline Then
              cnt.TextMode = TextBoxMode.MultiLine
      
      
          End If
      

      These are dynamically created fields. so what i want to do is to use this following JQuery on this textbox

      $(document).ready(function()
      {
      $("#contentbox").keyup(function()
      {
      var box=$(this).val();
      var main = box.length *100;
      var value= (main / 145);
      var count= 145 - box.length;

          if(box.length <= 145)
          {
          $('#count').html(count);
          $('#bar').animate({"width": value+'%',}, 1);
          }
          return false;
          });
      

      });

      and what this function does it count the number of Characters that have been typed in a Textbox. so i am displaying the remaining characters. So that is working fine on my example because the Element is known at Early Binding. Now my question is what if the textbox is created dynamically ?

      contentbox

      this is the name of the Textbox in my example. hOW do we use a J Query in Dynamically created Textbox. Thanks

      Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@dotnetfunda.com http://www.Dotnetfunda.com

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      You can use something like this:

      $("#" + "<%= cnt.ClientID %>").keyup(function() { /* ... */ });

      You will have to ensure you have access to "cnt" from that scope. Or store the value in ClientID in a variable that you then use on the page.

      Somebody in an online forum wrote:

      INTJs never really joke. They make a point. The joke is just a gift wrapper.

      1 Reply Last reply
      0
      • V Vimalsoft Pty Ltd

        Good Day All i am creating Textboxes at Runtime with something like this

        Dim cnt As New TextBox

            cnt.ID = "cont\_" & x
        
            If multiline Then
                cnt.TextMode = TextBoxMode.MultiLine
        
        
            End If
        

        These are dynamically created fields. so what i want to do is to use this following JQuery on this textbox

        $(document).ready(function()
        {
        $("#contentbox").keyup(function()
        {
        var box=$(this).val();
        var main = box.length *100;
        var value= (main / 145);
        var count= 145 - box.length;

            if(box.length <= 145)
            {
            $('#count').html(count);
            $('#bar').animate({"width": value+'%',}, 1);
            }
            return false;
            });
        

        });

        and what this function does it count the number of Characters that have been typed in a Textbox. so i am displaying the remaining characters. So that is working fine on my example because the Element is known at Early Binding. Now my question is what if the textbox is created dynamically ?

        contentbox

        this is the name of the Textbox in my example. hOW do we use a J Query in Dynamically created Textbox. Thanks

        Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@dotnetfunda.com http://www.Dotnetfunda.com

        A Offline
        A Offline
        AditSheth
        wrote on last edited by
        #3

        Instead of ID get the textbox using Class. give the class of textbox for example let i give a class name 'contentbox'

        cnt.cssClass = "contentbox"

        and in javascript

        $(".contentbox").keyup(function()

        V 1 Reply Last reply
        0
        • A AditSheth

          Instead of ID get the textbox using Class. give the class of textbox for example let i give a class name 'contentbox'

          cnt.cssClass = "contentbox"

          and in javascript

          $(".contentbox").keyup(function()

          V Offline
          V Offline
          Vimalsoft Pty Ltd
          wrote on last edited by
          #4

          Thank you very much , that did the Trick :)

          Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@dotnetfunda.com http://www.Dotnetfunda.com

          A 1 Reply Last reply
          0
          • V Vimalsoft Pty Ltd

            Thank you very much , that did the Trick :)

            Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@dotnetfunda.com http://www.Dotnetfunda.com

            A Offline
            A Offline
            AditSheth
            wrote on last edited by
            #5

            :thumbsup:Thanks

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups