jquery get textbox text valuehttp://forums.asp.net/t/1511814.aspx/1?jquery+get+textbox+text+valueWed, 10 Nov 2010 19:50:24 -050015118143604437http://forums.asp.net/p/1511814/3604437.aspx/1?jquery+get+textbox+text+valuejquery get textbox text value <pre class="prettyprint">&lt;script type=&quot;text/javascript&quot;&gt; $(document).ready(function() { $('.btnSubmit').click(function(e) { alert($(&quot;#txtName&quot;).val()); }); }); &lt;/script&gt;</pre> <p><br> hi</p> <p>I have a text box like this<font color="#0000ff" size="2"></p> <p></font><font color="#a31515" size="2">&lt;asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">TextBox</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;txtName&quot;</font><font size="2"> </font><font color="#ff0000" size="2">CssClass</font><font color="#0000ff" size="2">=&quot;txtName&quot;&nbsp;</font><font size="2">&nbsp;</font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">TabIndex</font><font color="#0000ff" size="2">=&quot;1&quot;</font><font size="2"> </font><font color="#ff0000" size="2">MaxLength</font><font color="#0000ff" size="2">=&quot;40&quot;&gt;&lt;/</font><font color="#a31515" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">TextBox</font><font color="#0000ff" size="2">&gt;</font><font size="2">&nbsp;</font></p> <p>&nbsp;<font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">HiddenField</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;hfName&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</font></p> <p>&nbsp;</p> <p>&nbsp;On form load</p> <p>txtName.Text = &quot;myname&quot;;</p> <p>how do i get the textbox value using jquery</p> <p>somehow this did not work</p> <p>&nbsp;</p> <p>thanks</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2010-01-07T20:17:33-05:003604485http://forums.asp.net/p/1511814/3604485.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p>Hi Urspalshu,</p> <p>If you've got an input with an id of txtEmail you should be able to use the following code to access the value of the text box:</p> <pre><pre class="prettyprint"><span>$</span><span>(</span><span>&quot;#txtEmail&quot;</span><span>).</span><span>val</span><span>()</span><span> </span></pre></PRE> <P>You can also use the val(string) method to set that value:</P><PRE jquery1262901805921="25"><pre class="prettyprint"><SPAN>&#36;</SPAN><SPAN>(</SPAN><SPAN>"#txtEmail"</SPAN><SPAN>).</SPAN><SPAN>val</SPAN><SPAN>(</SPAN><SPAN>"something"</SPAN><SPAN>)</SPAN><SPAN>&nbsp; </SPAN></pre></PRE></pre> 2010-01-07T21:04:05-05:003604507http://forums.asp.net/p/1511814/3604507.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p>thanks for your reply . seems like my alert is&nbsp; not returning the value...</p> <p>kindly help with sample....</p> <p>thanks</p> <p>&nbsp;</p> <p>&nbsp;</p> 2010-01-07T21:24:05-05:003604547http://forums.asp.net/p/1511814/3604547.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p>Try this.&nbsp; It works for me.</p> <p>&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;<br> &lt;head&gt;<br> &nbsp;&nbsp;&nbsp; &lt;title&gt;&lt;/title&gt;<br> &nbsp;&nbsp;&nbsp; &lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/jquery-latest.js&quot;&gt;&lt;/script&gt;<br> &nbsp;&nbsp;&nbsp; &lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;(function() {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;(&quot;#Button1&quot;).click(function() {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&#36;(&quot;#Text1&quot;).val());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp; &lt;/script&gt;&nbsp; &nbsp;<br> &lt;/head&gt;<br> &lt;body&gt;<br> &nbsp;&nbsp;&nbsp; &lt;input id=&quot;Button1&quot; type=&quot;button&quot; value=&quot;button&quot; /&gt;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp; &lt;input id=&quot;Text1&quot; type=&quot;text&quot; /&gt;&nbsp;&nbsp; &nbsp;<br> &lt;/body&gt;<br> &lt;/html&gt;</p> 2010-01-07T22:17:20-05:003606050http://forums.asp.net/p/1511814/3606050.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p>Thanks for your sample but I need to use asp TextBox and ImageButton to achieve the same. Kindly help with sample using this.</p> <p><font color="#a31515" size="2">&lt;asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">TextBox</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;txtName&quot;</font><font size="2"> </font><font color="#ff0000" size="2">CssClass</font><font color="#0000ff" size="2">=&quot;txtName&quot;&nbsp;</font><font size="2">&nbsp;</font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">TabIndex</font><font color="#0000ff" size="2">=&quot;1&quot;</font><font size="2"> </font><font color="#ff0000" size="2">MaxLength</font><font color="#0000ff" size="2">=&quot;40&quot;&gt;&lt;/</font><font color="#a31515" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">TextBox</font><font color="#0000ff" size="2">&gt;</font><font size="2">&nbsp;</font></p> <p><font color="#0000ff" size="2"></p> <p>&lt;</font><font color="#a31515" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">ImageButton</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;btnSubmit&quot;</font><font size="2"> </font><font color="#ff0000" size="2">CssClass</font><font color="#0000ff" size="2">=&quot;btnSubmit&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">ImageUrl</font><font color="#0000ff" size="2">=&quot;~/images/btnSubmit.jpg&quot;</font><font size="2">&nbsp;&nbsp;</p> </font> <p><font color="#ff0000" size="2">AlternateText</font><font color="#0000ff" size="2">=&quot;Submit&quot;</font><font size="2"> </font><font color="#ff0000" size="2">TabIndex</font><font color="#0000ff" size="2">=&quot;14&quot;</font><font size="2"> </font><font color="#ff0000" size="2">OnClick</font><font color="#0000ff" size="2">=&quot;btn_submit_Click&quot;</font><font size="2">&nbsp;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</font></p> <p>Thanks</p> 2010-01-08T14:36:37-05:003606658http://forums.asp.net/p/1511814/3606658.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p>It's the same code but here you go.</p> <p><style type="text/css"> <!-- span {font-family:"Courier New"; font-size:10pt; color:#000000; background:#FFFFFF} a {text-decoration:none; font-weight:bold; color:#000000} .S1 {color:#0000FF} --> </style><span>&lt;html xmlns=&quot;<span>http://www.w3.org/1999/xhtml</span>&quot; &gt;<br> &lt;head&gt;<br> &lt;title&gt;&lt;/title&gt;<br> &lt;script type=&quot;text/javascript&quot; src=&quot;<span>http://code.jquery.com/jquery-latest.js</span>&quot;&gt;&lt;/script&gt;<br> &lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;<br> &#36;(function() {<br> &#36;(&quot;#btnSubmit&quot;).click(function() {<br> alert(&#36;(&quot;#txtName&quot;).val());<br> });<br> }); <br> &lt;/script&gt; <br> &lt;/head&gt;<br> &lt;body&gt;<br> &lt;asp:ImageButton ID=&quot;btnSubmit&quot; CssClass=&quot;btnSubmit&quot; runat=&quot;server&quot; ImageUrl=&quot;~/images/btnSubmit.jpg&quot; AlternateText=&quot;Submit&quot; TabIndex=&quot;14&quot; OnClick=&quot;btn_submit_Click&quot; /&gt; <br> &lt;asp:TextBox ID=&quot;txtName&quot; CssClass=&quot;txtName&quot; runat=&quot;server&quot; TabIndex=&quot;1&quot; MaxLength=&quot;40&quot;&gt;&lt;/asp:TextBox&gt; <br> &lt;/body&gt;<br> &lt;/html&gt;<br> <br> <br> <br> </span></p> 2010-01-08T20:28:09-05:003606707http://forums.asp.net/p/1511814/3606707.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p>Hi Urpalshu,</p> <p>In ASPX:</p> <p><pre class="prettyprint">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head id=&quot;Head1&quot; runat=&quot;server&quot;&gt; &lt;title&gt;Untitled Page&lt;/title&gt; &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt; $(function() { $(&quot;#&lt;%= btnSubmit.ClientID %&gt;&quot;).click(function() { alert($(&quot;#&lt;%= txtName.ClientID %&gt;&quot;).val()); var isPostbackRequired = false; /// Do your stuff to make isPostbackRequired true /// or false so as to postback or not return isPostbackRequired }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;asp:TextBox ID=&quot;txtName&quot; CssClass=&quot;txtName&quot; runat=&quot;server&quot; TabIndex=&quot;1&quot; MaxLength=&quot;40&quot;&gt;&lt;/asp:TextBox&gt; &lt;asp:ImageButton ID=&quot;btnSubmit&quot; CssClass=&quot;btnSubmit&quot; runat=&quot;server&quot; ImageUrl=&quot;~/images/btnSubmit.jpg&quot; AlternateText=&quot;Submit&quot; TabIndex=&quot;14&quot; OnClick=&quot;btn_submit_Click&quot; /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre><br> </p><p><br></p><p>In Codebehind:</p><p><pre class="prettyprint">using System; using System.Collections.Generic; using System.Text; using System.Web.UI; public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { txtName.Text = "myname"; } } protected void btn_submit_Click(object sender, ImageClickEventArgs e) { //Do your stuff here } } </pre><br> <br> </p> <p><br> </p> 2010-01-08T21:07:44-05:003937429http://forums.asp.net/p/1511814/3937429.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p>Unfortunately this method is now incorrect and will throw an exception error in the .NET compiler.</p> <p>A better method is to use the name like selector of jQuery:</p> <p></p> <pre class="prettyprint">&lt;asp:Textbox ID=&quot;txtTest&quot; runat=&quot;server&quot; /&gt; $(&quot;input[name*='txtTest']&quot;).val():</pre> <p><br> <br> </p> <p></p> <p><br> </p> <p><br> </p> 2010-06-21T12:48:34-04:003937603http://forums.asp.net/p/1511814/3937603.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p></p> <blockquote><span class="icon-blockquote"></span> <h4>G0ggy</h4> <p></p> <p>Unfortunately this method is now incorrect and will throw an exception error in the .NET compiler.</p> <p>A better method is to use the name like selector of jQuery:</p> <p><br> </p> &lt;div class=&quot;dp-highlighter&quot;&gt;&lt;div class=&quot;bar&quot;&gt;&lt;div class=&quot;tools&quot;&gt;<a href="#">view plain</a><a href="#">copy to clipboard</a><a href="#">print</a><a href="#">?</a><br> &lt;/div&gt;&lt;/div&gt; <ol class="dp-xml" start="1"> <li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">asp:Textbox</span><span>&nbsp;</span><span class="attribute">ID</span><span>=</span><span class="attribute-value">&quot;txtTest&quot;</span><span>&nbsp;</span><span class="attribute">runat</span><span>=</span><span class="attribute-value">&quot;server&quot;</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&#36;(&quot;input[name*='txtTest']&quot;).val():&nbsp;&nbsp;</span></li></ol> &lt;/div&gt;<pre class="prettyprint">&lt;asp:Textbox ID=&quot;txtTest&quot; runat=&quot;server&quot; /&gt; $(&quot;input[name*='txtTest']&quot;).val():</pre> <p></p> </blockquote> <p></p> <p>Or this: <span>&#36;(&quot;input[id&#36;=txtTest]&quot;).val()</span></p> <p><span>That will search in reverse for the input id.&nbsp; Perfect for ASP.NET MasterPages<br> </span></p> 2010-06-21T14:11:22-04:004163332http://forums.asp.net/p/1511814/4163332.aspx/1?Re+jquery+get+textbox+text+valueRe: jquery get textbox text value <p>Thank you for that tip! &nbsp;That saved me a lot of FindControl() / ClientID headache.</p> 2010-11-10T19:50:24-05:00