Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Hidden element be accessed by javascript getElementByName?

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?

like image 978
Vikas Avatar asked Apr 16 '09 11:04

Vikas


2 Answers

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();
like image 67
Canavar Avatar answered Sep 28 '22 03:09

Canavar


Not sure of the context but shouldn't you be using getElementById ??

like image 21
Shaun Bohannon Avatar answered Sep 28 '22 04:09

Shaun Bohannon