Hey everyone,

I'm workin on a little side project and I was looking for some help. Currently I have code that will check a given directory and populate two list boxes based on id3 tag information. The first select box will be populated with artist info and the second, with album info. What I want to do is use javascript to populate the second list box with the album info matching the artist selected, hence the "onChange" in the forum post title. Below is a portion of my code. I believe you can get the overall picture of what is going on. It has many calls to php methods that are not defined below but i think you can see what they are doing/returning etc.

Could someone point me in the right direction of how to use javascript to populate the second select box only when an artist is selected and not before? Thanks!

//Fetch array containing filenames/paths to music directory
    $fileArray = listdir('directory path goes here');
    
    echo '<html><head>';
    echo '</head><body>';
    echo '<table><tr><td>Artist</td><td>Album</td></tr>';
    echo '<tr><td><select size="10" name="Artists"><option selected value="">';
    
    $artists = array();
    
    foreach($fileArray as $filename) {
        $myId3 = new getTags($filename);
        if($errors[$myId3->last_error_num] == 0) {
            if ($myId3->getInfo()){
                if(!in_array($myId3->getArtist(), $artists)) {
                    echo '<option value="'.$myId3->getArtist().'">'.$myId3->getArtist().'</option>';
                    array_push($artists, $myId3->getArtist());
                }
            }
        }
    }
    echo '</select></td>';
    echo '<td><select size=\"10\">';
    
    $albums = array();
    
    foreach($fileArray as $filename) {
        $myId3 = new getTags($filename);
        if($errors[$myId3->last_error_num] == 0) {
            if ($myId3->getInfo()){
                if(!in_array($myId3->getAlbum(), $albums)) {
                    echo '<option value="'.$myId3->getAlbum().'">'.$myId3->getAlbum().'</option>';
                    array_push($albums, $myId3->getAlbum());
                }
            }
        }
    }
    
    echo '</select></td>';
    echo '</tr></table>';
    echo '</body></html>';

I'd just like to be a bit more specific. That second foreach loop i would like to be dynamic so is there a way to call a javascript function that will pass the artist selected and then just call the php function, passing that artist to the function?

Thanks again.

This article has been dead for over six months. Start a new discussion instead.