I have a hidden field
<input type="hidden" name="smname" />
Now i have a function in a js file count(); How can I assign the return value to the hidden field?
I have a hidden field
<input type="hidden" name="smname" />
Now i have a function in a js file count(); How can I assign the return value to the hidden field?
Share Improve this question asked Feb 18, 2012 at 12:38 user1199657user11996574 Answers
Reset to default 14You could give your hidden field an unique id:
<input type="hidden" name="smname" id="smname" />
and then in javascript:
document.getElementById('smname').value = count();
where count is the function you want to invoke and which returns the value:
var count = function() {
return 'some value';
};
Try:
document.getElementsByName('smname')[0].value = count();
You want to use code such as
document.getElementById("name")
then deal with it as an object. remember to define a name/id for your html element.
If you give the input element an id
attribute you will be able to get a reference to it in javascript using the document.getElementById()
method then set the value
property of the element
HTML
<input id="surname" type="hidden" name="smname" />
Javascript
var input = document.getElementById("surname");
input.value = count();