Casper Round Casper Round - 2 years ago 194
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>

Answer Source

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()});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download