How to get text from a textbox using javascript <p>i have developed a web application using mvc4.</p> <p>in this case i need to get a text box value(actually the text entered in the text box) using javascript.</p> <p>here is the code i am using</p> <pre><code> @model PortalModels.WholeSaleModelUser @using (Html.BeginForm("uploadFile", "WholeSaleTrade", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;WholeSaleModelUser&lt;/legend&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Name) &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;div class="editor-field"&gt; @Html.TextBoxFor(model =&gt; model.Name) @Html.ValidationMessageFor(model =&gt; model.Name) &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div id="partial"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;img id="blah" src="../../Images/no_image.jpg" alt="your image" height="200px" width="170px" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;script type="text/javascript"&gt; function loadUserImage() { var userImg = document.getElementById("blah"); var imgNm = $("#Name").value; userImg.src = "D:/FEISPortal/FortalApplication/Img/" + imgNm + ".png"; alert(imgNm); alert(userImg.src); } &lt;/script&gt; </code></pre> <p>in that case alert gives the value as "undefined" and if do the following modification alert gives nothing.</p> <pre><code>var imgNm = document.getElementById("Name").value; </code></pre> <p>for</p> <pre><code>var imgNm = $("#Name").value; </code></pre> <p>how to get the text entered in the text box?</p>