/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Dropdown box to switch CSS files problem.

Hello All,

I have the following code in a webpage:

[code]
<form name=”list”>
<select name=”sheets” onchange=”setActiveStyleSheet(document.list.sheets.options[document.list.sheets.selectedIndex].value); return false;”>
<option selected value=”test”>Test
<option value=”test2″>Test2
<option value=”test3″>Test3
</select>
[/code]

So far so good, this code works!
but.. it’s not XHTML strict compliant.
How can I make it so that this is completely XHTML compliant?

If I change the “name” into “id” and use the getItemById the code doesn’t work anymore. (could be because I did something wrong.

Can anyone point me in the right direction?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 04.2009 — &lt;form action="#" id="list"&gt;
&lt;div&gt;
&lt;select name="sheets" onchange="setActiveStyleSheet(this.value); return false;"&gt;
&lt;option selected="selected" value="test"&gt;Test&lt;/option&gt;
&lt;option value="test2"&gt;Test2&lt;/option&gt;
&lt;option value="test3"&gt;Test3&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt; <br/>
&lt;/form&gt;
Copy linkTweet thisAlerts:
@amarthauthorMar 04.2009 — Thanks! Works like a charm!

Super quick reply!
Copy linkTweet thisAlerts:
@amarthauthorMar 04.2009 — Just one more question...

If I were to make it an onclick instead of onchange by removind the onchange and adding:

<i>
</i>&lt;INPUT type="button" name="go" value="Go!" onClick="setActiveStyleSheet(document.getelementbyid(list).value); return false;"&gt;


This doesn't work... and I think I know why... because I'm not getting the value. How can I get the value from the list ?
Copy linkTweet thisAlerts:
@FangMar 04.2009 — &lt;[COLOR="Blue"]input[/COLOR] type="button" name="go" value="Go!" [COLOR="Blue"]onclick[/COLOR]="alert(document.[COLOR="Blue"]getElementById[/COLOR]('list').sheets.options[document.getElementById('list').sheets.selectedIndex].value); return false;" [COLOR="Blue"]/[/COLOR]&gt;
http://www.w3.org/MarkUp/2004/xhtml-faq

Learn JavaScript and html before embracing xhtml
×

Success!

Help @amarth spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...