I saw a question in a forum asking how to show content based on which value was displayed chosen in a select box. I threw together this small sample to illustrate one way you could do this using jQuery.
The full HTML file is attached.
Code Snippet
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title></title>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- });
- // Event Handler for the OnChange event of the Select1
- function SelectedItemChanged() {
- // Gets the value of Select1
- var x = $("select#Select1").val();
- // Ensures that the corresponding paragraph is visible
- ShowItem(x);
- // Loops through all of the options for Select1 and hides them if they aren’t the selected option
- $("select#Select1 option").each(function(i) {
- if ($(this).val() != x) {
- HideItem($(this).val());
- }
- });
- }
- function ShowItem(alpha) {
- $("#changingArea #" + alpha).show();
- }
- function HideItem(alpha) {
- $("#changingArea #" + alpha).hide();
- }
- </script>
- </head>
- <body>
- <select id="Select1" name="Select1" onchange="javascript:SelectedItemChanged();">
- <option>A</option>
- <option>B</option>
- <option>C</option>
- <option>D</option>
- <option>E</option>
- </select>
- <div id="changingArea">
- <div id="A">Paragraph 1</div>
- <div id="B">Paragraph 2</div>
- <div id="C">Paragraph 3</div>
- <div id="D">Paragraph 4</div>
- <div id="E">Paragraph 5</div>
- </div>
- </body>
- </html>