简体   繁体   中英

Set the value of textbox in Bootstrap Modal from label text

I am showing the bootstrap modal on clicking the hyperlink.Beside the hyperlink there's a label in which some text is getting printed dynamically.

I am getting the text of that specific label using jquery to print it in Textbox present in Bootstrap Modal.

The text is retrieved very fine but i could not get successfull in showing this text is bootstrap Modal Textbox.

Here is my Jquery Code :

<script>
    $(function () {
        $(".edit").click(function () {    
            var tr = $(this).parent().parent();
            var tdRecords = $(tr).children();
            var CurrValue = $(tdRecords[0]).text();
            var NewValue = $(tdRecords[1]).text();
            alert(CurrValue); //alert is showing the value fine
            $("#Curr_Val").val(CurrValue); //not working
            $('#myModal').modal('show');
        });
    });
</script>

Here is my Modal Code :

<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Edit Information</h4>
            </div>
            <div class="modal-body">
              <div class="row">
                  <div class="col-md-3">
                      Current Value :
                  </div>
                  <div class="col-md-6">
                      <asp:TextBox CssClass="txtstyle" runat="server" ID="Curr_Val"></asp:TextBox>
                  </div>
              </div>
                <div class="row">
                  <div class="col-md-3">
                      New Value :
                  </div>
                  <div class="col-md-6">
                      <asp:TextBox CssClass="txtstyle" runat="server" ID="New_Val"></asp:TextBox>
                  </div>
              </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary">Save Changes</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
            </div>

        </div>
    </div>
</div>

The value is getting printed in alert very fine but it's not getting printed in textbox.

Someone Please Help me what am I missing.

Thanks in advance

The problem with accessing asp net controls using jquery way. You need to change it to $('#<%= Curr_Val.ClientID %>').val(CurrValue);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM