and in javascri...">

Can a hidden element be accessed using javascript getElementByName?

I have a hidden field like

<%= Html.Hidden("ID", 1) %>

and in javascript i want the value of this field

var ID = document.getElementsByName("ID").value;

I can’t access it!

Is there another way?

+5
source share
5 answers

Not sure about context, but should not use getElementById ??

+3
source

Try the following:

<input type="hidden" id="ID" />

for javascript to access it:

var ID = document.getElementById("ID").value;

in another way using jQuery:

var ID = $('#ID').val();
+4
source

, :

var id = document.getElementById('id').value;
+1

id:

<% Html.Hidden("ID", 1, new { id = "MyHidden"}) %>

document.getElementById("MyHidden").value
+1
  • getElementsByName(name) name.
  • getElementById(id) id.
  • getElementsById - .
  • getElementsByID, getElementByID - javascript. !

Answering the question:

You can get the identifier of a hidden element if it is hidden on the client side. (You can see it in the generated source.)

document.getElementById('ID').value;

Or something like that.

+1
source

All Articles