I am trying to add hide/show select boxes on my page. The way it should work is that when I select a category, associated sub-category select box will show up, otherwise no sub-category select box is shown. my trouble is that I can't get sub-category select box show up when i select proper category. Can anyone give me a hand on this. below is the my code:
<script type="text/javascript" src="[% c.uri_for("/static/js/effects.js") %]"></script>
<script type="text/javascript" src="[% c.uri_for("/static/js/controls.js") %]"></script>
<script type="text/javascript">
function parentChosen (parenty) {
parent = $(parent);
var children = document.getElementsByClassName('child');
for (i = 0; i < children.length; i++) {
Element.hide(children);
children.getElementsByTagName("select")[0].disabled = true;
}
var child = $("parent_"+parent.value+"top_children(3)")
if (child) {
child.show();
childChosen(child);
child.getElementsByTagName("select")[0].disabled = false;
}
else {
childChosen(null);
}
}
function childChosen (child) {
child = $(child);
}
Event.observe( window, 'load',
function () {
Event.observe( 'parent', 'click', function () { parentChosen('parent'); } );
Event.observe( 'parent', 'keypress', function () { parentChosen('parent'); } );
parentChosen( 'parent' );
}
);
</script>
......
<div class="parent" style="">
<label for="parent">[% loc('Category') %] :</label>
<select name="parent" id="parent">
<option value=""></option>
[% FOREACH cat IN categories %]
<option value="[% cat.category_id %]">[% cat.title %]</option>
[% END %]
</select>
</div>
[%-CALL categories.reset; %]
[% FOREACH category IN categories -%]
[% children = category.top_children( 3 ) %]
[% IF children %]
<div class="child" style="display;" id="children"><br>
<label for="child">
[% loc( 'Sub-category' ) %] :
</label>
<select name="child">
<option value=""></option>
[% FOREACH child IN children %]
<option value="[% child.get_column( 'id' ) %]">[% child.title %]</option>
[% END %]
</select>
</div>
[% END %]
[%- END %]
<script type="text/javascript" src="[% c.uri_for("/static/js/effects.js") %]"></script>
<script type="text/javascript" src="[% c.uri_for("/static/js/controls.js") %]"></script>
<script type="text/javascript">
function parentChosen (parenty) {
parent = $(parent);
var children = document.getElementsByClassName('child');
for (i = 0; i < children.length; i++) {
Element.hide(children);
children.getElementsByTagName("select")[0].disabled = true;
}
var child = $("parent_"+parent.value+"top_children(3)")
if (child) {
child.show();
childChosen(child);
child.getElementsByTagName("select")[0].disabled = false;
}
else {
childChosen(null);
}
}
function childChosen (child) {
child = $(child);
}
Event.observe( window, 'load',
function () {
Event.observe( 'parent', 'click', function () { parentChosen('parent'); } );
Event.observe( 'parent', 'keypress', function () { parentChosen('parent'); } );
parentChosen( 'parent' );
}
);
</script>
......
<div class="parent" style="">
<label for="parent">[% loc('Category') %] :</label>
<select name="parent" id="parent">
<option value=""></option>
[% FOREACH cat IN categories %]
<option value="[% cat.category_id %]">[% cat.title %]</option>
[% END %]
</select>
</div>
[%-CALL categories.reset; %]
[% FOREACH category IN categories -%]
[% children = category.top_children( 3 ) %]
[% IF children %]
<div class="child" style="display;" id="children"><br>
<label for="child">
[% loc( 'Sub-category' ) %] :
</label>
<select name="child">
<option value=""></option>
[% FOREACH child IN children %]
<option value="[% child.get_column( 'id' ) %]">[% child.title %]</option>
[% END %]
</select>
</div>
[% END %]
[%- END %]