update < option > tag's 'selected' attribute according to url's city value

moviemenvideo

New Member
This is my URL: www.xyz.com/index?city=NYI am trying to update < option > tag's 'selected' attribute according to url's city value.This is my partial html:\[code\] <script> function loadCity(val) { window.location.assign("/do/index?city="+val); //script that reload's page as per selected city value. } $(document).ready ( function(){ var cityValue= http://stackoverflow.com/questions/15687163/<?=$_GET['city'] ?>; var k = getElementById(cityValue); k.option.setAttribute('selected', true); });? //this function not working </script><select id="city" onchange="loadCity(this.value)"> <option>Cities</option> <?php $cities=get_cities(); ?> //get cities from an array <?php foreach($cities as $city): ?> <option id="<?= $city?>" value="http://stackoverflow.com/questions/15687163/<?= $city?>"><?= $city?></option> <?php endforeach; ?> </select>\[/code\]Tried a bunch of other stuff, nothing seams to work.Thanks in advance.(your response is greatly appreciated!)
 
Back
Top