How to retrieve hidden field value using javascript?

Priyanka picture Priyanka · Dec 2, 2011 · Viewed 10.5k times · Source

I've asp.net web site , I used master page for the design. I've child page which is placed in the contentplaceholder. On the child page i used one hidden field as -

<input id="Hidden1" type="hidden" value="This is hidden text"/>

I want to display the hidden field value using alert() function from javascript on the page load event. How to do this?

I tried following thing in my script but it is not working-

(function msgShow() {

        var e1 = document.getElementById('Hidden');
        alert(e1.value);
    })();

Thanks.

Answer

Cyclonecode picture Cyclonecode · Dec 2, 2011

With jQuery you do like this:

$(document).ready(function() {
    alert($('#Hidden1').val());
});

without jQuery you do:

alert(document.getElementById('Hidden1').value);