I want a page to have a different item pre-selected in an option menu-button according to the parameter at the end of the URL. Eg if the URL ends in "?choice=Beta", the item that says "Beta" should be pre-selected. Here's what I have so far:

Code:
<script type="text/javascript">
function show(choice) { 
  var success = -1;
  for (var i=0; i < document.frmInput.cboNames.length; i++) {
    if (document.frmInput.cboNames.options[i].text == choice) 
      success = [i];
  }
  document.frmInput.cboNames.selectedIndex=success;
} 

var choice = location.href.split("?")[1].split("=")[1];
document.write('<p>Choice: ' + choice + '</p>');
show(choice);
</script>

<form name="frmInput">
  <p>Choice: 
  <select name="cboNames">
    <option value="1">Alpha</option>
    <option value="2">Beta</option>
    <option value="3">Gamma</option>
    <option value="4">Delta</option>
  </select>
  </p>
  <p><input type=button name="btnInput" value="Choose" onclick="var choice = location.href.split('?')[1].split('=')[1];show(choice);"></p>
</form>
I know the parameter (choice) is being picked up OK, because of the first paragraph - generated by "document.write()". And I know the code for selecting the right item ("show()") is OK because of the "Choose" button. But why doesn't "show(choice)" get triggered right after "document.write('<p>Choice: ' + choice + '</p>')"?

I know I could put an "onload" into my body element, but it's not that easy to do that because this page is to be part of a CMS-driven site.

Thanks.