CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    [RESOLVED] How to use Jquery on a Dynamical created Textbox

    Good Day All

    i am creating Textboxes at Runtime with something like this

    Code:
    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

    Code:
    $(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 ?

    content-box
    .

    this is the name of the Textbox in my example.

    hOW do we use a J Query in Dynamically created Textbox.


    Thanks
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: How to use Jquery on a Dynamical created Textbox

    I typically use Java and pass the current object to the Script...
    PHP Code:
    onclick="JavaCode(this);" onkeyup="JavaCode(this);" onchange="JavaCode(this);" 
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Re: How to use Jquery on a Dynamical created Textbox

    Instead of ID get the textbox using Class.

    i give the class of textbox for example let i give a class name 'contentbox'

    Code:
    cnt.cssClass = "contentbox"
    and in javascript

    Code:
    $(".contentbox").keyup(function()
    and it worked , thanks
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured