I cannot alter the code of the select box in this case, so I must use javascript to change it after the select box has loaded. There are several pages, some with several select boxes, that need this function. I would like one javascript function that will take take two variables (the form element and a value) and then set the correct option to be selected.
Here is an example of the code format for these select boxes. I can add id or value attributes to the options but this would be a very time consuming process as there are a large number that would need to be edited.
[HTML]
<select name="userans0" id="userans0">
<option></option>
<option>CR - Copy Recorded</option>
<option>CU - Copy Unrecorded</option>
<option>OU - Original unrecorded</option>
<option>OR - Original recorded</option>
<option>MI - Missing</option>
</select>
[/HTML]
Here is the javascript function I am trying to use, this is in the document header.
Expand|Select|Wrap|Line Numbers
- function selectValue(formElement, val)
- {
- for(i=0;i<formElement.length;i++)
- {
- if(formElement.options[i].value==val)
- {
- formElement.selectedIndex=i
- }
- }
- }
formElement = document.testform.userans0
val = CU - Copy Unrecorded
And the code to call the function.
[HTML]
<script type="text/javascript" language="JavaScript">
selectValueA(formElement, val);
</script>
[/HTML]
I can't seem to get this to work.