I am very new with HTML and PHP and the code below I have a drop down select box and a submit button which uses PHP (this is from an example) But I need help on how to allow the user to select a report name from the drop down and click the Submit button and open a excel spreadsheet. If "Position" is selected user clicks Submit button and the Excel file opens. First of all is that possible? And second then how do I accomplish? Thanks in advance. </body> </html> <ol> <form method="post" action="yourscript.php"> <select name="Reports"> <option value="Positions">Position <option value="Employees">Employees <option value="Transfers" selected>Transfers </select> </form> <td> </td> <td><input type="submit" value="Submit"></td> </tr> </form> </table> </form>
So, you have some excel files on your server that you uploaded? Or are you trying to create excel files on the fly from a database (like mysql)? ~alhen
Ok, well assuming that you just have some flat XLS files that you've already uploaded to your server... and those are the files you want to link to with your form... here's "A" way to do it. It's not very sophisticated, but it works. I just tested it. First of all, your form has too many tags. You've got a few extra </form> tags in there. This section is what should go on your form page (I named it form.html) Notice that for the "value" I typed in the actual file name. <html> <head> <title>Form Page</title> </head> <body> <form method="post" action="xl.php"> <select name="Reports"> <option selected>Choose Report</option> <option value="Positions.xls">Position</option> <option value="Employees.xls">Employees</option> <option value="Transfers.xls">Transfers</option> </select> <input type="submit" value="Submit"> </form> </body> </html> Code (markup): This section will be the page you're sending to. (I've named it xl.php and you can see that I've pointed to this page in the code above as the "action") <? $reports=$_POST['Reports']; ?> <html> <head> <title>Get Excel Report</title> <meta http-equiv="refresh" content="0; url=http://www.yourdomain.net/<? echo $reports?>"> </head> <body> </body> </html> Code (markup): The working part of this page is <? $reports=$_POST['Reports']; ?> PHP: which is taking what you sent fromt he page before "Reports" and giving it a variable name "$reports". Then we're echoing that variable name in the meta refresh tag: <? echo $reports?> PHP:
This could work with just javascript <form> <select name="Reports" id="reportlist"> <option selected>Choose Report</option> <option value="Positions.xls">Position</option> <option value="Employees.xls">Employees</option> <option value="Transfers.xls">Transfers</option> </select> <input type="submit" value="Get it!" onclick="get_report();"> </form> Code (markup): Then, in the header, or someplace on the page... <script language="javascript" type="text/javascript"> function get_report() { parent.location = "http://site.com/path/to/reports/" + document.getElementByID("reportlist").value; } </script> Code (markup):