I have this jquery code

<script type="text/javascript">

    $(document).ready(function () {

        var counter = 2;

        $("#addButton").click(function () {

            var newTextBoxDiv = $(document.createElement('div'))
         .attr("id", 'TextBoxDiv' + counter);

            newTextBoxDiv.after().html('<input class="required" data-val="true" data-val-regex="Provide a valid date." data-val-regex-pattern="^\d{1,2}\/\d{1,2}\/\d{2}$" name="Date[' + counter + ']" id="Date[' + counter + ']" value="Date[' + counter + ']" style="width:165px" type="text" />' + ' ' +
          '<input type="text" name="WorkHour' + counter +
          '" id="WorkHour' + counter + '" value="" style="width:175px" >');

            newTextBoxDiv.appendTo("#TextBoxesGroup");

            $.validator.unobtrusive.parseDynamicContent('TextBoxesGroup input:last');

            counter++;
        });

        $("#removeButton").click(function () {
            if (counter == 2) {
                alert("No more textbox to remove");
                return false;
            }

            counter--;

            $("#TextBoxDiv" + counter).remove();

        });

        $("#getButtonValue").click(function () {

            var msg = '';
            for (i = 1; i < counter; i++) {
                msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();
            }
            alert(msg);
        });
    });
</script>

Its generating a dynamic textbox also it's include removing.

I want to know if it is possible also to validate the dynamic textbox?

Member Avatar for LastMitch

I want to know if it is possible also to validate the dynamic textbox?

What do you mean validate the dynamic textbox? You mean a postback or without a postback?

You can take a look at this:

http://www.codeproject.com/Articles/43772/Generic-Code-of-Validating-Fields-with-Jquery

Is that what you are looking for?

You need to post the ASP.net code with the jQuery if that code from link is not what you are looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.