views:

550

answers:

1

I am populating a select box from jquery $.post();

The option values returned from the post have one option with " selected='selected' " but rather than setting the control to this option the last option in the string is selected and displayed.

The last option has it's selected property set to true but firebug shows the selected text against the correct option.

Any solutions.

EDIT

MARKUP :=
<select id='mailing_countries' ></select><br>

POST RETVAL :=
<option id='mailing_zone_50' value='19.95' selected="selected" >Saturday Delivery (£19.95)</option>
<option id='mailing_zone_11' value='7.95' >Next Working Day (£7.95)</option>
<option id='mailing_zone_6' value='4.95' >2-4 Working Days (£4.95)</option>

JS CODE :=
$('#mailing_countries').html(retval);
A: 

I've done that in the past, and it has worked for me. There must be something that isn't quite the same for you. You can take a JavaScript approach to selecting an option this way:

To change the selected option in a select box, you have to change its selectedIndex, like:

document.forms[0].select.selectedIndex = 2;

This is from quirksmode. There's more there so check it out.

geowa4