Icebergness Posted October 31, 2011 Share Posted October 31, 2011 Hi, I'm having a tough time combining two separate pieces of code. To summarise, I have an entire folder hierachy which I want to access via a group of dropdown boxes, so there is a box for months, a box for the dates and a box for the year. The code I have found on the internet (and slightly modified with the dates etc.) is this: <html> <head> <script language="javascript" type="text/javascript"> function jumpTo(url) { document.location.href=url; } </script> <script type="text/javascript"> var categories = []; categories["startList"] = ["January","February","March","April","May","June","July","August","September","October","November","December"] categories["January"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]; categories["February"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"]; categories["March"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]; categories["April"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]; categories["May"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]; categories["June"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]; categories["July"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]; categories["August"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]; categories["September"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]; categories["October"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]; categories["November"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]; categories["December"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]; categories["1"] = ["2008","2009","2010","2011"]; categories["2"] = ["2008","2009","2010","2011"]; categories["3"] = ["2008","2009","2010","2011"]; categories["4"] = ["2008","2009","2010","2011"]; categories["5"] = ["2008","2009","2010","2011"]; categories["6"] = ["2008","2009","2010","2011"]; categories["7"] = ["2008","2009","2010","2011"]; categories["8"] = ["2008","2009","2010","2011"]; categories["9"] = ["2008","2009","2010","2011"]; categories["10"] = ["2008","2009","2010","2011"]; categories["11"] = ["2008","2009","2010","2011"]; categories["12"] = ["2008","2009","2010","2011"]; categories["13"] = ["2008","2009","2010","2011"]; categories["14"] = ["2008","2009","2010","2011"]; categories["15"] = ["2008","2009","2010","2011"]; categories["16"] = ["2008","2009","2010","2011"]; categories["17"] = ["2008","2009","2010","2011"]; categories["18"] = ["2008","2009","2010","2011"]; categories["19"] = ["2008","2009","2010","2011"]; categories["20"] = ["2008","2009","2010","2011"]; categories["21"] = ["2008","2009","2010","2011"]; categories["22"] = ["2008","2009","2010","2011"]; categories["23"] = ["2008","2009","2010","2011"]; categories["24"] = ["2008","2009","2010","2011"]; categories["25"] = ["2008","2009","2010","2011"]; categories["26"] = ["2008","2009","2010","2011"]; categories["27"] = ["2008","2009","2010","2011"]; categories["28"] = ["2008","2009","2010","2011"]; categories["29"] = ["2008","2009","2010","2011"]; categories["30"] = ["2008","2009","2010","2011"]; categories["31"] = ["2008","2009","2010","2011"]; var nLists = 3; // number of select lists in the set function fillSelect(currCat,currList){ var step = Number(currList.name.replace(/\D/g,"")); for (i=step; i<nLists+1; i++) { document.forms['tripleplay']['List'+i].length = 1; document.forms['tripleplay']['List'+i].selectedIndex = 0; } var nCat = categories[currCat]; for (each in nCat) { var nOption = document.createElement('option'); var nData = document.createTextNode(nCat[each]); nOption.setAttribute('value',nCat[each]); nOption.appendChild(nData); currList.appendChild(nOption); } } function getValue(L3, L2, L1) { alert("Your selection was:- \n" + L1 + "\n" + L2 + "\n" + L3); } function init() { fillSelect('startList',document.forms['tripleplay']['List1']) } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); </script> </head> <body> <form name="tripleplay" action=""> <select name='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>Make a selection</option> </select> <select name='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>Make a selection</option> </select> <select name='List3' onchange="getValue(this.value, this.form['List2'].value, this.form['List1'].value)"> <option selected >Make a selection</option> </select> </form> </body> </html> Then I have some code that displays a folder's contents on screen: <?php ($_POST['tripleplay']) { $link = "../marketing/2011\February\20"; if (file_exists($link)) { if ($handle = opendir($link)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(!preg_match("/\.pdf$/", $file)) continue; { echo "<a href=\"".$link."/".$file."\">".$file."</a><br>"; } } } echo "<br>"; closedir($handle); } } break; ?> Basically I need for the results of the dropdown boxes to help select the folder. So for the above example, if the dropdown says February 20, 2011, it would display that folders contents. I'm sorry that this is such a mess, but I would be grateful for any help you can give Quote Link to comment https://forums.phpfreaks.com/topic/250167-dropdown-box-query/ Share on other sites More sharing options...
Psycho Posted October 31, 2011 Share Posted October 31, 2011 So, what exactly is the problem. What is it you want to happen and what is is doing differently? By the way, that is some crappy JavaScript code. You should programmatically determine the days in the month to avoid problems with leap years. Quote Link to comment https://forums.phpfreaks.com/topic/250167-dropdown-box-query/#findComment-1283686 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.