tags:

views:

75

answers:

2

If my jquery function is as below:

$('#shifts').change (function () 
    {

     $.get('ajax/time_menus.php', { shift: $('#shifts').val() },      
        function(data) 
     {
      $("#test").html( data );
      });

And returns a array with two time values contained in an array of six values: [hours][minutes][ampm][hours][minutes][ampm]

How would I set the values of 6 correlated menus as to display the two times I just loaded.

Is there a way to set the value via jquery or is it better to build the entire menu's in php and then pass them back and set the html.

A: 

With jQuery, you can select different <option>s with the val function:

$('#my-select').val(yourValue);
Ken Browning
But wont that set the value. I want to set the option of my choosing as <option selected>.
ian
Or if you mean.. it would set #my-select where -select finds the slected #my then wouldn't i end up with possibly two <options with the same value.
ian
I read your post as asking "how do I select an `option` of a `select` via jQuery". If theres misunderstanding going on then you might edit your question to be clearer.
Ken Browning
This does not select the item, it merely sets the value of the <select> element. This does not automatically select the appropriate option.
idrumgood
@idrumgood: wrong. proof: <select id="test-select"> <option value="val1">option1</option> <option value="val2">option2</option></select><script> $(function() { alert('changing'); $('#test-select').val('val2'); });</script>
Ken Browning
+1  A: 
$('#my-select option[value="yourValue"]').attr('selected','selected');
idrumgood