Dropdown menus
On occasion, a webmaster will want a select field on their web site to act like a drop-down menu: A way of opening a certain page simply by expanding the menu and clicking a certain option.
As an example:
The first is simply a part of a larger form, where you select an option and move on. The second one is meant to perform an action (page change) as soon as a selection is made.
But when using this normal setup, you still need to click a "Submit" button that will execute the form. Obviously, the less clicks are required, the better.
On the other hand, simply using the following will break the page for non-Javascript users:
<form action="showforum.php" method="get"> <select name="forum" onchange="this.form.submit();"> <option value="1" selected="selected">General</option> <option value="2">Tech Support</option> <option value="3">Miscellaneous</option> </select> </form>
And if you violate the rules of accessibility, Tim Berners-Lee will turn in his grave.
...that is, he would if he were dead. But it's things like this that can send the W3C to an early grave. Anyway.
So what you want is to display a submit button to the user agents who do not execute scripts, but hide it from the users who do.
Solution? Watch and learn.
<head> <!-- if javascript works, hide the button --> <script type="text/javascript">
document.test.button1.style.display="none";
</script> </head> <body> ... <form id="test" action="showforum.php"> <select onchange="this.form.submit();"> <option value="1" selected="selected">General</option> <option value="2">Tech Support</option> <option value="3">Miscellaneous</option> </select> <input type="submit" id="button1" name="" value="Go" /> </form> ... </body>
- 475 reads

Post new comment