Casper Round Casper Round - 4 months ago 8x
jQuery Question

Javascript option change head style.css

I have a relatively simple form with an option to select the theme.
What I need is javascript to view the current selected option and change the style.css file depending on its class. For example, if Dark where selected in the option it would need to reokace style.css with dark.css
Here is my select code:

<option value="<?= $_SESSION['user']['theme']?>">Current</option>
<option value="volvo">Dark</option>
<option value="saab">Light</option>
<option value="mercedes">Grass</option>
<option value="audi">Audi</option>


Try this example:

1) set css file path in option value


<link id="stylesheet" rel="stylesheet" href="//">
<select id="themes">
  <option value="">Le Frog</option>
  <option value="">Start</option>
  <option value="">Smoothness</option>
  <option value="">Redmond</option>
  <option value="">Sunny</option>
<input type="submit" value="A submit button">

2) as select option changes get that value and change link css file path

    $("#stylesheet").attr({href : $('#themes').val()});