I've got a form with some field to post. There is two dropdowns (select - options). If the user doesn't fill all required fields, the form appear again after the post, and the correct values should be present.
The first dropdown gets filled stright from the database. The options in the second dropwdown depends on the selected one in the first dropdown. The first dropdown works just fine, the option is present, and selected with $('#area').val(area); The options is present in the second dropdown (filled with jQuery.getJSON). My problem is that I can't get the option to be selected as with the first dropdown, even if I hardcode $('#daytime').val(daytime), that is daytime is different given values (so there should not be a problem using the right value). I've tried to set $('#daytime').val(daytime) in the same script as the first one, that both choose the option in the first dropdown and fills the second dropdown but no luck so far. I've also tried to create it's own script just to select the option. So, it works in the first case, but not the other one. Any help would be much appreciated. /jonas CODE SNIPPET: <script type="text/javascript"> jQuery(document).ready(function(){ var area = <?php echo $_SESSION['signup_area']; ?> $('#area').val(area); var selectedArea = jQuery("#area option:selected"); if(selectedArea.val() != 0) { jQuery.getJSON ("daytime.php", { id: selectedArea.val() }, function(j) { jQuery('#daytime options').remove(); var options = '<option value="">Välj</option>'; for (var i = 0; i < j.length; i++) { options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>'; } jQuery("#daytime").html(options); } ); // end getJSON } // *** this part doesn't work *** var daytime = <?php echo $_SESSION ['signup_day_time']; ?> $('#daytime').val(daytime); }); <select name="area" style="width: 190px" id="area"> <option value="0">Välj</option> <?php $db =& JFactory::getDBO(); $db->setQuery ('SELECT * FROM area ORDER BY id'); $rows = $db->loadObjectList(); foreach ($rows as $item) { echo '<option value="'.$item->id.'">'.$item->theArea.'</ option>'; } ?> </select> <select name="daytime" style="width: 190px" id="daytime"> <option value="0">Välj</ option> </select> Download this as a file