views:

55

answers:

3

the thing is that I have a form with a textbox and a button and a hidden field, now what i want to do is to write something in the textbox ,pass it to the hidden field and then access that thing written in the hidden field in the controller . how can i do that?

+1  A: 

Why do you need a hidden field for that? If you have a textbox, then on form submit, the value from the textbox will be directly available.

I might not understand you correctly, but from what it looks, your textbox's value will always have the same value as the hidden one..

What exactly are you trying to accomplish then?

Artiom Chilaru
+2  A: 

Why Hidden Feild? You can simply pass the Value of TextFeild using Jquery on Button Click?

Below the code:-

$(document).ready(function(){ $("#Create").click(function(){ var data1 = $('#TextField').val(); $.ajax({ type:"Post", url:'/Controller/SomeFunction', data:"Name="+ data1, success:function(result) { alert(result); }, error:function(result) { alert("fail"); } }); }); });
SAHIL SINGLA
+3  A: 

You can use OnSubmit form event, and javascript to copy data from TextBox to the hidden field. Here is a simple html exmple:

<html>

<head>
<script type="text/javascript">
function AddDataToHidden()
{
  document.getElementById('test').value = document.getElementById('login').value;
}
</script>
</head>

<body>
  <form action="action.aspx" onsubmit="javascript:return AddDataToHidden();" method="get">
    <input type="text" id="login" name="login" />
    <input type="hidden" id="test" name="test" />
    <input type="submit" />
  </form>
</body>
</html>
msi
For best usage you can change document.getElementById('test') to jQuery selectors, if you are using jQuery.
msi