Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hide/show select box question

Status
Not open for further replies.

jj0914

Programmer
Aug 4, 2006
33
CA
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 %]
 
Thanks Dan, I will get those things corrected and see if that works.
 
Dan, I used FireBug to detect any typo and called suparentChosen(), i still can't get it work. I have no clue why. I just got to use javascript, sorry about my lack of knowledge.

Johnny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top