user2860130
user2860130

Reputation:

How to get value from javascript alert to textbox in asp.net

The value must be retrived from javascript alert to textbox without losing runat="server". code as follow

<script type="text/javascript">
    $(".btn-group > button.btn").on("click", function () {
        var name = this.innerHTML; ;
        $('#TextBox1').html(name); 
    });
</script>

Upvotes: 0

Views: 629

Answers (2)

Anant Dabhi
Anant Dabhi

Reputation: 11104

  <script type="text/javascript">
        $(".btn-group > button.btn").on("click", function () {
            var name = this.innerHTML; ;
    // Use `val()` instead of html
    // Use `ClientID ` to use textbox generated id in javascript
            $('#<%= TextBox1.ClientID%>').val(name); 
        });
    </script>

Upvotes: 1

Gulfaraz Rahman
Gulfaraz Rahman

Reputation: 407

$('#TextBox1').val(name);

Use the value method to set the content of the text box

Upvotes: 0

Related Questions