Re: changing items of SELECT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




There are two standard ways of doing this, both using Javascript/PHP.

1) Use an onchange handler in the first <select>, which when 
triggered, causes your page to reload, passing through the ID of the 
selected artist.  Then, you can run a database query against this 
artist ID to get all the albums.

2) When the script loads, extract all albums for all artists (ordered 
by artist ID) from the database and load each artists' albums into 
its own javascript array (you'll need some association with the 
artist ID in the name of the array).  Then, use an onchange handler 
in the first <select> which when triggered, empties the second 
<select> and refills it with the albums stored in the javascript 
array with a matching artist ID. [see 
http://www.mattkruse.com/javascript/dynamicoptionlist/ for more 
details on how this works]

There are pros and cons to each approach.  Option one is less 
database-intensive, but needs a refresh which may irritate/confuse 
users.  Option two is very database-intensive, particularly if your 
db stores a lot of artists/albums.  The choice of which to use will 
probably depend on this amount of data.

Hope that helps,
Brian

--- In php-objects@xxxxxxxxxxxxxxx, "syothgandolfi" <syoth@xxxx> 
wrote:
> 
> 
> Hi!
> 
> I have something like this:
> 
> <form ...>
> ...
> <select name="artist" id="artist">
> <option...
> </select>
> <select name="album" id="album">
> </select>
> ...
> </form>
> 
> When the user select an artist, I have to fill "album" with the 
> artist's albums (from my database).
> 
> Anyone knows how can I do this?
> 
> Ty





PHP Data object relational mapping generator - http://www.meta-language.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux