I have Hidden field like
<%= Html.Hidden("ID", 1) %>
and in javascript i want a value of that field by
var ID = document.getElementsByName("ID").value;
I can't access it!
is there any other way?
I have Hidden field like
<%= Html.Hidden("ID", 1) %>
and in javascript i want a value of that field by
var ID = document.getElementsByName("ID").value;
I can't access it!
is there any other way?
Not sure of the context but shouldn't you be using getElementById ??
Perhaps what you want to be doing is:
var id = document.getElementById('id').value;
Try this :
<input type="hidden" id="ID" />
for javascript to access it :
var ID = document.getElementById("ID").value;
other way with JQuery :
var ID = $('#ID').val();
id do this:
<% Html.Hidden("ID", 1, new { id = "MyHidden"}) %>
document.getElementById("MyHidden").value
getElementsByName(name)
returns an array of elements with the given name property.getElementById(id)
returns the element with the given id property.Answering the question:
You can get the id of a hidden element if it is hidden client side. (You can see it in the generated source.)
document.getElementById('ID').value;
Or something like this.