Thank The Cheese
Registered
Hello everyone,
I have written a tutorial for students about accessible use of JavaScript. One of the sections is on using <noscript> to provide alternative info in case JavaScript has been turned off.
Example page set up here.
The script looks like this:
As you can see, the page generates a select box that uses JavaScript to allow the user to select an option and be taken to that website immediately. If JS has been disabled, then a hypertext version of the menu displays.
A simple example of the power of <noscript> and is made possible by placing the select box code in document.write so that it does not appear if JS has been disabled.
Problem is document.write is no longer valid according to the W3C's 2.0 guidelines, because of incompatibility with XHTML, so I need to update this exercise with something that is more compliant.
The W3C's suggestion on how to fix this is a little bit over my head, as I have very limited knowledge of JavaScript. I just can't seem to make heads or tails of it. I've looked everywhere for a straightforward tutorial on how to achieve the same as above without using document.write but I can't seem to find anything.
I was hoping someone here might be able to help me? Or point me in the right direction to an online tutorial I may have missed.
Any help greatly appreciated!
I have written a tutorial for students about accessible use of JavaScript. One of the sections is on using <noscript> to provide alternative info in case JavaScript has been turned off.
Example page set up here.
The script looks like this:
Code:
<script type="text/javascript">
<!--
document.write('<select onchange="if (this.selectedIndex > 0) location.href=this[this.selectedIndex].value;"><option selected="selected">Choose a destination</option><option value="http://www.google.com">Google</option><option value="http://www.apple.com">Apple</option><option value="http://www.w3.org">W3C</option></select>')
-->
</script>
<noscript>
<h1>Choose a Destination:</h1>
<a href="http://www.google.com">Google</a><br />
<a href="http://www.apple.com">Apple</a><br />
<a href="http://www.w3.org">W3C</a>
</noscript>
As you can see, the page generates a select box that uses JavaScript to allow the user to select an option and be taken to that website immediately. If JS has been disabled, then a hypertext version of the menu displays.
A simple example of the power of <noscript> and is made possible by placing the select box code in document.write so that it does not appear if JS has been disabled.
Problem is document.write is no longer valid according to the W3C's 2.0 guidelines, because of incompatibility with XHTML, so I need to update this exercise with something that is more compliant.
The W3C's suggestion on how to fix this is a little bit over my head, as I have very limited knowledge of JavaScript. I just can't seem to make heads or tails of it. I've looked everywhere for a straightforward tutorial on how to achieve the same as above without using document.write but I can't seem to find anything.
I was hoping someone here might be able to help me? Or point me in the right direction to an online tutorial I may have missed.
Any help greatly appreciated!