Link to home
Start Free TrialLog in
Avatar of bmanmike39

asked on

How do I get the value from a textbox and assign it to a hiddenField in JS, using Html helper hidden field cod? MVC4 ASP.NET

I have a textbox that I would like to assign the values to the hidden field, when i submit the form. How would I do this?  I'm using Html helper  and don't know how to 1, assign a id to it. And 2, how to access the textbox and put it in the hidden field.

Code:  js
<script type="text/javascript">
                    function gqt()
                        var x = document.getElementById("quantity").value;

Open in new window

Code: view
<form method="post" action="script">

                   @Html.Label("Quantity:") <input id="quantity" type="text" value="1"/>
                   @Html.Hidden("itemNumber", ViewData["numberId"].ToString())
                   @Html.Hidden("quantity", ????)

                   <input class="btn btn-danger" type="submit" value="Add Info" onclick="gqt()" />

Open in new window

Avatar of Lokesh B R
Lokesh B R
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bmanmike39


don't I have to use jquery for this?

jQuery will be simple to use.

you can even use the JavaScript.
Thanks for the help!!