Reputation: 3317
I'm trying to make a quick CSS style switcher from a dropdown in HTML. The JS is external, and called at the end of the head right before the form.
My JS:
function ChangeTheTheme(){
txt = document.getElementsByTagName("link");
switch(document.mytheme.themes.selectedIndex) {
case 0:
alert("Choice 0");
txt[0].href = "style.css";
break;
case 1:
alert("Choice 1");
txt[0].href = "style2.css";
break;
}
}
HTML line that matters is :
<form name="mytheme">
<select name=”themes” onChange=”ChangeTheTheme();”>
I tried adding alert("working");
in the beginning of the function. It's showed me that the function isn't being called at all.
The dropdown should switch CSS styles to whatever's currently selected. No buttons to submit or anything. That's what I understand onchange
should do.
Upvotes: 0
Views: 194
Reputation: 53311
You had fancy quotes instead of normal quotes. (this often happens when copying from Wordpress-powered blogs, be careful when you do so! I copied a PHP code from a Wordpress blog once, it crashed my blog for a while until I could figure out what was going wrong...)
<select name="themes" onChange="ChangeTheTheme();">
Upvotes: 7