Tuesday, January 29, 2013

Add Dynamic textboxes using Jquery

<head>
<script type="text/javascript">
function AddMoreTextboxes() {
    var counter = 1;
    var firstTextboxValue = $("#txtselectedValue").val();
    if (firstTextboxValue == '') {
        alert('Enter the value in First Textbox !');
        return;
    }
    else {
        if (counter > 5) {
            alert("Only 5 textboxes allow");
            return false;
        }
        var newTextBoxDiv = $(document.createElement('div'))
             .attr("id", 'TextBoxDiv' + counter);

        newTextBoxDiv.attr("class", "newTextBoxDiv");

        newTextBoxDiv.after('<label></label>' + '<input type="text" name="textbox' + counter +
            '" id="textbox' + counter + '" />').html('<label></label>' +
            '<input type="text" style="width:200px;" class="newTextbox" name="textbox' + counter + '" id="textbox' + counter + '" value="" />');

        newTextBoxDiv.appendTo("#TextBoxesGroup");
        counter++;
    }
}
</script>
</head>
<body>
<div>
<img src="../../Images/plus.png" width="16" height="16" id="ImgAddMoreTextbox" onclick="AddMoreTextboxes();" />
</div>
</body>

No comments:

Post a Comment