This is my URL: www.xyz.com/index?city=NY I am trying to update < option > tag's 'selected' attribute according to url's city value. This is my partial html:
<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= <?=$_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="<?= $city?>"><?= $city?></option>
<?php endforeach; ?>
</select>
Tried a bunch of other stuff, nothing seams to work. Thanks in advance.(your response is greatly appreciated!)