0

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

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by vuyiswamb
0

To get the text box is very simple, you can use the class selector to match all text boxes with that class:

<script>
    $(".contentbox").keyup(function()
    {
        ...
    });
</script>

<input type="text" class="contentbox" />

For each dynamically created text box you will have an count box? If so you'll have to change your code to get the nearest count box from the current typing text box.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.