lelewin
lelewin

Reputation: 559

getting the value of textbox of Grid

Now , I am using ASP.net with C# . I have a Grid and there are two text box controls in it. How should I do to get the value of these two text box controls from JavaScript.

Regards

Upvotes: 0

Views: 294

Answers (2)

talha2k
talha2k

Reputation: 25493

You can get the value of text box in grid view through java script as follows:

Just add a call to a javascript function on onblur or on keypress or any other event you want, of the textbox control you want to get the value of, like following:

<ItemTemplate>
     <asp:TextBox ID="TextBox1" OnBlur = "javascript:return DefaultValue(this);"
     runat="server" Text='1'>
     </asp:TextBox>
</ItemTemplate>

Now in script tag creat a function like this:

function DefaultValue(name) {
            var value = document.getElementById(Name.id).value;
            alert(value);
}

Hope This Helps.

Upvotes: 1

Muad&#39;Dib
Muad&#39;Dib

Reputation: 29256

this example will get the control that has an id of "theIDOfMyTextBox" and then place the text into the variable text

<script type="text/javascript">
    var textBox = document.getElementById("theIDOfMyTextBox");
    var text = textBox.value;
</script>

WC3 Schools has an online javascript editor that you can use, as does google

Upvotes: 0

Related Questions