Hi J,
j_*****@hotmail.com wrote:
Is something like this possible?
A form with x fields named
field1, field2, ... fieldx
I'd like to set the field specified in the parameter
function SetUnknownField(FieldID)
{
document.myform.field+FieldID+.value="Something calculated";
}
Any help would be appreciated.
Yes, you have the right idea. So for example, let's say your form was
like so:
<form action = "uri" method = "post" name = "myForm" id = "myForm">
<input type = "text" name = "field1"/>
<input type = "text" name = "field2"/>
[etc.. fieldx]
</form>
Within your javascript function, you could have the following:
function SetFieldValue(fieldName, fieldValue)
{
document.forms["myForm"].elements[fieldName].value = fieldValue;
}
This way, you can specify any field name and any value that you want to
set it to. If you wanted to modify, you could even pass in the form
name.
Hope this helps. :)