how to get hidden element value in javascript
+2
A:
If the element has an id attribute and if it has a value attribute then you can use value property
document.getElementById ( "hidElem" ).value;
for a hidden input element like
<input type='hidden' id='hidElem' />
otherwise you can use innerText property
document.getElementById ( "hidElem" ).innerText;
for a hidden div element like
<div style='display: none' id='hidElem'>value of hidden element</div>
rahul
2010-01-01 13:43:14
A:
Putting ids on all your elements is overkill in my opinion. You can access them by their name attribute - all you need is a reference to the form object.
<form id="blah">
<input type="hidden" name="inputOne" value="1" />
<input type="hidden" name="inputTwo" value="2" />
</form>
var formObj = document.getElementById('blah');
alert("Input one value: " + formObj.inputOne.value);
alert("Input two value: " + formObj.inputTwo.value);
This applies to all types of form input.
nickf
2010-01-01 14:03:36