locked
Jquery text box value RRS feed

  • Question

  • User-1578974752 posted

    I am new to jquery
    how can i update the below jquery in such a way that,

    When I click Button1,then Textbox1 value will change to next number(If current value is 1 then it will change to 2 and will keep on increment on each click). Thanks

      <script src="../Scripts/jquery-3.3.1.js"></script>
        <script>
            $(function () {
                $("#Button1").click(function () {
                    $("#Panel1").clone().appendTo("#form1")
                //clone the content of panel


                })


            })
            var clone_table_template;
    $(document).ready(function() {
        clone_table_template = $('.clone_table').clone();
     });
    $('.add_more_field').click(function() {
      $('.clone_wrapp').append(clone_table_template);
    });
        </script>

    Monday, February 18, 2019 5:42 AM

Answers

  • User475983607 posted

    The code sample is too confusing to guess what you are trying to do but increment a variable is very simple.

    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>
    
    <input id="Button1" type="button" value="button" />
    <input id="Text1" type="text" name="Text1" />
    
    @section  scripts{
        <script>
            var count = 0;
            $('#Text1').val(count++);
            $('#Button1').click(function (e) {
                $('#Text1').val(count++);
            });
    
        </script>
    }
    
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 18, 2019 1:02 PM

All replies

  • User475983607 posted

    The code sample is too confusing to guess what you are trying to do but increment a variable is very simple.

    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>
    
    <input id="Button1" type="button" value="button" />
    <input id="Text1" type="text" name="Text1" />
    
    @section  scripts{
        <script>
            var count = 0;
            $('#Text1').val(count++);
            $('#Button1').click(function (e) {
                $('#Text1').val(count++);
            });
    
        </script>
    }
    
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 18, 2019 1:02 PM
  • User-1578974752 posted

    above query is to clone a panel with 2 grid views. Now when I click button, then the values of gridviews are also copied to the cloned panel. So I thought to place a where condition in the gridview ,so that based on  that value the grid view will show the values .On the next click of add panel, the textbox value will increment to 2 so that the cloned gridview will not have any values..not sure whether this idea will work..or any other suggestion ,please advice.

    My intension is to click add panel button and on each click of the button ,new panel with 2 empty gridviews(only with header must apper).that is possible only if select statement of gridviews with where condition
    where ID=@ID and with below parameters
     
                  <SelectParameters>
                      <asp:ControlParameter ControlID="textbox1" Name="ID" PropertyName="Text" Type="Decimal" />
                  </SelectParameters>
                  </asp:SqlDataSource>
        

    On each add panel button click the textbox value increment to 1 means the cloned panel will have no value.Is there any way that i could make this happen..? Thanks

    Tuesday, February 19, 2019 2:57 AM