Ron Aronica wrote:
I want to specify the value of an input field using the return from a
function. I want to do something this this:
<script>
function value() {
return "the value";
}
</script>
<form>
<input name="theValue" type="hidden", value=value()>
</form>
but it does not work. How do I accomplish this?
Thanks
Hi,
Just set it like you set any other field:
before i show you how, you should first use good syntax.
1) Name your form, so you can adres it!
2) <input name="theValue" type="hidden", value=value()>
is bad.
It should be:
<input name="theValue" type="hidden", value="someValueHere">
3) better use the following scripttag:
<script type="text/javascript">
Now you can do the following:
I added a button to fire an event which I use to set your value to the
hidden field. Of course I don't know how you will use it, this is just used
to call the function setHiddenValue().
-------------------------------------
<script type="text/javascript">
function value() {
return "the value";
}
function setHiddenValue(){
hiddenvalue=value();
document.forms["myForm"].theValue.value=hiddenvalue;
}
</script>
<form name="myForm">
<input name="theValue" type="hidden" value="">
<input type="button" value="Click me to set hidden value"
onClick="setHiddenValue()">
</form>
-------------------------------------
I coded an extra function to show how things work.
You can also put the whole logic into 1 line.
setting a simple value always works like this:
document.forms["*formname*"].*formelementname*.value=*newvalue*;
Hope that helps you.
Regards,
Erwin Moller