views:

46

answers:

3

What would be the best approach to this?

Thanks

A: 

The easiest way to do this is to use jQuery.

For example:

var categoryItems = {
    'Car':             [ 'Acura', 'Honda', 'Toyota' ],
    'Computer:         [ 'Dell', 'HP', 'Lenovo' ],
    'Search engine':   [ 'Google', 'Bing', 'Yahoo' ]
};
$('#category').change(function() {
    var itemsDropdown = $('#items').empty();
    var items = categoryItems[$(this).val()];
    for(var i = 0;  < items.length; i++)
        itemsDropdown.append($('<option />').text(items[i]));
});
SLaks
How would I go about doing it? I have a list of locations, and when a location is selected I want to show a list of regions within that location.
Probocop
Which ID's are #category and #items referring to? and where would I put that javascript?
Probocop
The IDs of the two dropdown lists. You would put this in a `$(function() { ... });` call in a `<script>` block.
SLaks
Hmm I'm still not there, could you possibly post an example including some html?
Probocop
I will not write all of your code for you. You need to learn Javascript.
SLaks
I was not after you to do it for me, I merely wanted to see how to implement it, so I could learn. But nevermind, thanks anyway.
Probocop
A: 

you cant do dynamic like this via simple html. You should use javascript for example. In google there are a lot of solutions, this is one of them: http://programmersforum.ru/showpost.php?p=227550&amp;postcount=3

Skay
+1  A: 

Try this tread.

Alexander Vakrilov