You must Sign In to post a response.
  • Category: ASP.NET

    How to Add another text box value in this jquery code

    How to Add another text box value in this jquery code
    i want to get the value of dynamic text box value on button click.
    in this query i can add one text box value that is DynamicTextBox1.

    also am created another one that is DynamicTextBox2, all is working fine. but i cant able to get the DynamicTextBox2 value exavtly.

    so please help me to am get and add the another(DynamicTextBox2) one text box value to this jquery.


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(function () {
    var values1 = eval('<%=Values1%>');
    var values2 = eval('<%=Values2%>');

    if (values1 != null) {
    var html = "";
    $(values1).each(function () {
    var div = $("<div />");
    div.html(GetDynamicTextBox(this));
    $("#TextBoxContainer").append(div);
    });


    }

    $("#btnAdd").bind("click", function () {
    var div = $("<div />");
    div.html(GetDynamicTextBox(""));
    $("#TextBoxContainer").append(div);
    });
    $("body").on("click", ".remove", function () {
    $(this).closest("div").remove();
    });
    });
    function GetDynamicTextBox(value) {
    return '<input name = "DynamicTextBox1" type="text" value = "' + value + '" /> '+'<input name = "DynamicTextBox2" type="text" value = "' + value + '" /> '+
    '<input type="button" value="Remove" class="remove" />'
    }

    </script>
    </head>
    <body>
    <form id="form1" runat="server">

    <input id="btnAdd" type="button" value="add"/>
    <br />
    <br />
    <div id="TextBoxContainer">
    <!--Textboxes will be added here -->
    </div>
    <br />
    <asp:Button ID="btnPost" runat="server" Text="Post" OnClick="btnPost_Click" />
    </form>
    </body>

    Thanks with
    Paul.S
  • #767936
    Hi,

    I feel you can make it simple like this,
    When DynamicTextbox1 entered same time DynamicTextbox2 also got the same values.

    <!DOCTYPE html>
    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>
    $(".valueEnter").click(function () {

    $('#message').html($('#textBox').val());

    });
    </script>
    </head>

    <body>

    <div>
    TextBox 1 : <input type="textbox" id="textBox" class="valueEnter"></input>

    TextBox 2 : <input type="textbox" id="message"></input>
    </div>

    </body>
    </html>


    In Jquery you can add the coding for textbox1 so any changes will reflect to textbox2.


    $("#textBox").keyup(function(){
    $("#message").val($(this).val());
    });


    Hope this is helpful.

    Thanks,
    Mani

  • #767947
    So you want to get a dynamically created textbox value right ? see below snippet

    < input type="text" id="student_grde_G[1]" value="1">
    < input type="text" id="student_grde_G[2]" value="1">
    < input type="text" id="student_grde_G[3]" value="1">
    < input type="button" id="save_grade_button" class="button" value="Save Grades">

    $('#save_grade_button').click(function () {
    $.each($('[id^=student_grde_G]'), function (i, item) {
    var grade = $(this).val();
    alert(grade);
    });
    });

    just put this code on HTML file and try with it

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments