Title: pass a value from javascript to html
Tags: javascript;html
Question: I have a hidden field
<input type="hidden" name="smname" /&gt;
Now i have a function in a js file count(); How can I assign the return value to the hidden field?

Here is the accepted answer: You could give your hidden field an unique id:
<input type="hidden" name="smname" id="smname" /&gt;
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';
Comment for this answer: Or with JQuery:
$("#smname").val( count );

Here is another answer: 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.

Here is another answer: 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
<input id="surname" type="hidden" name="smname" /&gt;
Javascript
var input = document.getElementById("surname");
input.value = count();

Here is another answer: document.getElementsByName('smname')[0].value = count();

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 4, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:02/18/12', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<javascript><html>', 'Title': 'pass a value from javascript to html', 'ViewCount': 51822, 'id': 9341209, 'user_AboutMe': None, 'user_AccountId': None, 'user_DisplayName': None, 'user_Reputation': None, 'user_Views': None, 'user_id': None}}