troubleshooting Question

JS: HTML Select "SELECTED" parameter

Avatar of willsherwood
willsherwood asked on
JavaScript
2 Comments1 Solution1817 ViewsLast Modified:
When i displayPHP-generated SELECT dropdown lists, it's easy to insert SELECTED in the appropriate <option> that matches the current value in PHP.

I have now the situation of a static html <SELECT> list  of  States and Provinces.
I would like to have SELECTED programatically applied thru JS according to a PHP-generated variable.
Thus I need a JS function or statement  that somehow does the SELECT even tho the STATES dropdown list is static in html.

What code can i use for this?
In the following excerpt example, say that i can insert   <?=$SelectedStateAbbreviation?>  wherever it's needed in the JS.

<SELECT name=State >
<option value='CA'>California </option>
<option value='GA'>Georgia</option>
<option value='MA'>Massachusetts</option>
</select>


thanks!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros