I have two select boxes. I need so that: when an option on one select box is selected, PHP opens a file (based on the value of the option selected). The information inside the file needs to be read and used to create options in the second select box. I believe I know how to read the file and then possibly echo the options (if the php code is inside a javascript function), but the problem is that the filename is based on the selected option in the first select box. I'm not sure how to pass the value of that variable into the php code, so that PHP knows what file to open. Submitting a form is not an option because then it redirects the page. To make this easier to understand, here is the actual page I am dealing with: http://uglyduck.homeip.net/musicTest.php There is a select box of saved playlists. The names of the playlists are the same names as the filenames. In the file, each line contains a filename to a song. I want so that when you select a playlist and click "Load", that it will create an option for each listed song in the "current playlist" select box. I have been suggested to use XMLHttpRequest from another forum. I have tried this but can't seem to be able to get it to work. If this is the correct way to do this, helping me with this exact case or similar code examples would be nice. Thanks to anyone that can help me with this issue.
I've tried that and nothing happened... Maybe you can help me fix it? Here is what I had... Here is my javascript function called when "Load" button is clicked function loadPlaylist() { var name = saveList.options[saveList.selectedIndex].value; http = new ActiveXObject("Microsoft.XMLHTTP"); http.onreadystatechange=httpChange(); http.open('GET', "loadPlaylist.php?id=" + name, true); http.send(null); } function httpChange() { if(http.readyState==4) { var response = http.responseText; document.getElementById('playList').innerHTML = response; } } HTML: Here is loadPlaylist.php <?php $name = $_GET['id']; $File = "ftp://uglyduck.homeip.net/Music/" . $name . ".txt"; $Handle = fopen($File, 'r'); $Data = fgets($Handle); $Data = substr($Data, 7); $Data2 = substr($Data, 4); $data3 = '<option value="/Music/50 Cent - Best Friend.mp3">50 Cent - Best Friend'; fclose($Handle); echo $data3 ?> PHP: Until I get this to work I just have $data3 as a static option to make sure its formatted right and all. With this code, I get a "Type mismatch" error when Load is pressed. if i change the line: http.onreadystatechange=httpChange(); HTML: to: http.onreadystatechange=httpChange; HTML: I dont get the error, but nothing happens at all Thanks
Your page is taking more time for me to load. I have not tested your code but some of my points are here. You can move options from one to other without submitting the form. Even you can control the second drop down from the option selected from the first list using JavaScript . If you want to move options from one to other then you can see this demo For you JavaScript solutions are better than going for server side solutions. Just try HTH
That's not exactly what I'm trying to do. I already accomplish that through javascript from songlist to current playlist. I need to OPEN A SERVER-SIDE FILE with the filename being the selected option in the "saved playlist" select box this file has songnames on each line of a text file they need to be read in and create options with those song names in another select box.
Use flash as a media player, and javascript to communicate the current song-to-play to the flash player.