Return the value of a JS function and use it as the value for an input button

html, javascript

Solution

you could do:

<input type="button" id="s1" value="" />
<script type="text/javascript">
 var elem = document.getElementById("s1");
 elem.value = "some text";
</script>

Problem

I want to set a JavaScript function which returns a string, and that string to be used as a value for a button. Something like this: ``` function test(){ x = "some text"; return x; } ``` I want to use this function in a input element in the value attribute. Something like this: ``` <input type="button" id="s1" value="test()" /> ``` Unfortunatly the button doesn't show "some text" but "test()" on the button. How can i fix this?

Original source