1

If I am able to select an option from a drop down menu, then is it possible for that element which I selected will open up another drop down menu automatically with the the list of items that are under that particular category. The database is in XML and I'm coding in PHP.

Here's an example:

<html>
<head>
<script>
function showCD(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getcd.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
Select an Artist:
<select name="cds" onchange="showCD(this.value)">
<option value="">Select a CD:</option>
<option value="Bob Dylan">Bob Dylan</option>
<option value="Bonnie Tyler">Bonnie Tyler</option>
<option value="Dolly Parton">Dolly Parton</option>
</select>
</form>
<div id="txtHint"><b>Artist info will be listed here...</b></div>

</body>
</html>

Now, if I select say Bob Dylan, I would want another list of all his CDs showing in the next menu - for example - the code should be automated from an XML database - and the form should be something like this:

<form>
Select a song:
<select name="albums" onchange="showCD(this.value)">
<option value="">Select an Album:</option>
<option value="Album #1">Album #1</option>
<option value="Album #2">Album #2</option>
<option value="Album #3">Album #3</option>
</select>
</form>

Then after an album is selected, another form will pop up asking to select the Song, like this:

<form>
Select a song:
<select name="songs" onchange="showCD(this.value)">
<option value="">Select a Song:</option>
<option value="Song #1">Song #1</option>
<option value="Song #2">Song #2</option>
<option value="Song #3">Song #3</option>
</select>
</form>

I want to do this automated from a user's point of view, so I pick an artist from the list, and the data is ALL in an XML file. Then from that artist list another drop down menu is automatically generated with all his albums and then from that drop down list another menu is generated from all his songs in that album. Then I get his song to select and play.

I am using PHP, JavaScript/Jquery and AJAX and XML.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jose Sanchez
  • 7
  • 1
  • 6

0 Answers0