引用下拉框

I have this code to verify that.

<script type="text/javascript"> <!-- alert("Testing"); --> </script>

This code now makes a popup box on form page. All working as expected! Now the problem I'm having is referencing the drop-down box. I thought the following code should have done the trick but no.

var element; var i=EG;
element=document.getElementById("client_country"); element.selectedIndex = i;

But I cant seem to get it to work. I think its due to the use of frames, anyone able to point me in the direction of where I’m going wrong?

var i = 'EG'; // string inside quotes
var element = document.getElementById("client_country");
element.value = i; // set the selected option

// selectedIndex retrieves the value
var selected_value = element.options[element.selectedIndex].value;

This assumes you have HTML similar to...

<select id="client_country">
    <option value="AG">value a</option>
    <option value="CG">value c</option>
    <option value="EG">value e</option>
</select>

Working demo on JSFiddle.