user339160
user339160

Reputation:

How to Read the value in a hiddenField from javascript

I want to read a value in the hidden field in javascript/Jquery.How can i acheive this ??

Upvotes: 0

Views: 461

Answers (5)

Sergey
Sergey

Reputation: 8071

This an example to read and write value just with pure javascript.

<input type="hidden" id="field-id" />

<script type="text/javascript">
    document.getElementById('field-id').value = "your value which you want to insert";
    alert(document.getElementById('field-id').value);
</script>

Upvotes: 0

ojlovecd
ojlovecd

Reputation: 4892

<input type="hidden" value="12345" id="ixd" name='ixd' />

var val = document.getElementById("ixd").value;

Upvotes: 0

Matt H
Matt H

Reputation: 6532

Use the field name or id, e.g.

var fVal = $('[name="name"]').val();
var fVal = $('#id').val();

Upvotes: 0

Ariel
Ariel

Reputation: 26753

It's the same as for a regular field:

document.forms[xxx].elements[yyyy].value

xxx is the name of the form, or its number. yyyy is the name of the element (or its number).

You can also use document.getElementById() to get either the form or the field.

Upvotes: 0

Null Pointer
Null Pointer

Reputation: 9289

try this

var value=$('#HidennfieldID').val()

value will hold the value of hidden field

Upvotes: 4

Related Questions