Drop down table and jquery
Posted
by
Marcelo
on Stack Overflow
See other posts from Stack Overflow
or by Marcelo
Published on 2010-12-25T14:20:43Z
Indexed on
2010/12/25
15:54 UTC
Read the original article
Hit count: 265
Hi,
I'm trying to make a drop down table using jQuery, with a similar code like here: (from the topic: Conditional simple drop down list?)
<body>
<div id="myQuestions">
<select id="QuestionOptions">
<option value="A">Question A</option>
<option value="B">Question B</option>
</select>
</div>
<div id="myAnswers">
<div id="A" style="display: none;">
<div id="QuestionC">
<p>Here is an example question C.</p>
</div>
<div id="QuestionD">
<select id="QuestionOptionsD">
<option value="G">Question G</option>
<option value="H">Question H</option>
</select>
</div>
</div>
<div id="B" style="display: none;">
<div id="QuestionE">
<p>Here is an example question E.</p>
</div>
<div id="QuestionF">
<select id="QuestionOptionsF">
<option value="I">Question I</option>
<option value="J">Question J</option>
</select>
</div>
</div>
</div>
And the jQuery part
$(function () {
$('#QuestionOptions').change(function () {
$('#myAnswers > div').hide();
$('#myAnswers').find('#' + $(this).val()).show();
});
});
My problem is, when I finish to table the part of "myQuestions", and start to table the part of "myAnswers", the dynamic part of the table doesn't work. In this case, the myAnswers part won't be hidden, it'll be shown since the beginning. I tried to put everything in one table, then I tried to create a different table for myQuestions, then another table for myAnswers and it didn't work. Does anyone know where am I mistaking ?
Sorry for any mistake in English, I'm not a native speaker. Thanks in advance.
© Stack Overflow or respective owner