.NET Framework Bookmark and Share   
 index > JScript for the .NET Framework > How do I get the value of a textbox.Can anyone help!
 

How do I get the value of a textbox.Can anyone help!

I try to access a the text of a textbox.But I dont know how to do it.After I create var d var d = document.getElementById("TextBox1");

Can anyone help!

@Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

DOCTYPEhtml PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

htmlxmlns="http://www.w3.org/1999/xhtml" >

headrunat="server">

<title>Untitled Page</title>

headscriptlanguage="javascript" type="text/javascript">

ValidateUserName()

var d = document.getElementById("TextBox1");

scriptbody <form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server" CausesValidation="True"></asp:TextBox>

<br />

<asp:Button ID="Button1" runat="server" Text="Button" CssClass="StandardButton"OnClientClick="javascript:return ValidateUserName();" /></div>

</form>

bodyhtml

Code Snippet

htmlxmlns="http://www.w3.org/1999/xhtml" >

headid="Head1" runat="server">

<title>Untitled Page</title>

head <script language="javascript" type="text/javascript">

ValidateUserName()

var d = document.getElementById("TextBox1");

window.alert(d.value);

scriptbody <form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server" CausesValidation="True"></asp:TextBox>

<br />

<asp:Button ID="Button1" runat="server" Text="Button" CssClass="StandardButton" OnClientClick="ValidateUserName();" /></div>

</form>

bodyhtml

Code Snippet

htmlxmlns="http://www.w3.org/1999/xhtml" >

headid="Head1" runat="server">

<title>Untitled Page</title>

head <script language="javascript" type="text/javascript">

ValidateUserName()

var d = document.getElementById("TextBox1");

window.alert(d.value);

scriptbody <form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server" CausesValidation="True"></asp:TextBox>

<br />

<asp:Button ID="Button1" runat="server" Text="Button" CssClass="StandardButton" OnClientClick="ValidateUserName();" /></div>

</form>

bodyhtml

I tried to use something similar to that to get a value out of a text box, but get "document.getElementById('tbDescription') has no properties" in FireFox and "object required" in IE.

[code]

<asp:TextBox id="tbDescription" runat="server" Height="78px" TextMode="MultiLine" onkeypress="check()" Width="363px"></asp:TextBox>

<asp:RequiredFieldValidator id="rfvDescription" EnableClientScript="true" runat="server" ControlToValidate="tbDescription"

Display="none" ErrorMessage="You must give a description of your shipment." Font-Bold="True"

SetFocusOnError="True" ValidationGroup="quickQuote"></asp:RequiredFieldValidator>

<cc1:ValidatorCalloutExtender id="co_rfvDescription" runat="server" TargetControlID="rfvDescription"></cc1:ValidatorCalloutExtender>

[/code]

Javascript Function

[code]

<script language="javascript" type="text/javascript">

function check()

{

var x = document.getElementById('tbDescription').value;

alert(x);

}

</script>

[/code]

Thanks....

RRocket
WTF

It is't working in my VWD 2008 ..

M tearing ma hair Out...

Damn ____
Papaas
well m using ajax tab container in ma form ..there is a textbox target by ajax calender control .. and on blur there is a func of javascript .. that works well with static text .. but wn i alert the text of that textbox.. it is't working..

Note: I ve tried every possible combination of "" , '' , using ClientID, using <% %> , and also the by passing that as arg ..
if i ld ve tried on smfing else ,, i ld surely b able to suck ma ____
Papaas

You can use google to search for other answers

Custom Search

More Threads

• I want to display alert box with options
• Activex create problem in vista/ie7-ie8
• DLR support
• JScript cant draw and display coordinates properly
• Help converting code to JScript
• Calling a javascript function from Content page
• Problem with using dll with <object> in ASP.NET
• Scope chaining, variable objects and ect. Gurus are wanted!!!
• Where the J2EE Application Server Stands in the Scheme of Things
• Problem displaying data in DropDownList control while writing