For some reason I am having a hard time using the value of an option in a select dropdown. Here is the code:
<select id="select_category" name="select_category">
<option value=""></option>
<option value="home">Home</option>
<option value="office">Office</option>
<option value="dinning_room">Dinning Room</option>
</select>
<script>
var select_category = document.getElementById("select_category");
select_category.options["home"].selected = true;
</script>
When I run this I get the error "Cannot set propery 'selected' of undefined. If I replace ["home"] with [2] in the last line it works. Why can't I reference the option via the value I assigned to it?
Thanks
EDIT - as suggested, changed the javascript to this below, but now I get the error "token ILLEGAL"
document.getElementById('select_category').value = 'home';