I am trying to pre-populate form selections by evaluating a string. I will import a dynamic string later, but wanted to focus on the search function. If the value has a match in the string then write "selected" in the input tag to select it for the viewer. What am I doing wrong?
<script type="text/javascript">
function match_search(search_option) {
var myRegExp = /search_option/;
var string1 = "specialty1,specialty2,specialty3,specialty4";
var match1 = string1.search(myRegExp);
if(match1 != -1)
document.write("selected");
// End Result in form <option id="specialty2" value="specialty2" selected>specialty2</option>
else
document.write("");
}
</script>
</head>
<BODY>
<!-- multi_search -->
<table><tr><td>
<select value name="specialty" size="5" multiple id="specialty">
<!-- <option id="specialty2" value="specialty2" selected>specialty2</option> -->
<option id="specialty1" value="specialty1" onload="match_search(specialty1)">specialty1</option>
<option id="specialty2" value="specialty2" onload="match_search(specialty2)">specialty2</option>
<option id="specialty3" value="specialty3" onload="match_search(specialty3)">specialty3</option>
<option id="specialty4" value="specialty4" onload="match_search(specialty4)">specialty4</option>
<option id="specialty5" value="specialty5" onload="match_search(specialty5)">specialty5</option>
<option id="specialty6" value="specialty6" onload="match_search(specialty6)">specialty6</option>
</select>
</td></tr></table>