ternto333 Posted November 14, 2007 Share Posted November 14, 2007 I have multiple buttons in one form. One of the actions is to another PHP page which generates a CSV file, and uses headers to let the user download that file. The problem I'm having is that after pressing this button, if the user then wants to press another button, it performs the previous button's action. My javascript looks like this: if(document.pressed == 'peptide_csv') { document.summary_form.action ="peptide_view_csv.php"; } else if(document.pressed == 'reset_peptide') { document.summary_form.action ="peptide_view.php"; } In this case, if the user presses the peptide_csv button, it redirects him to peptide_view_csv.php. The code for this peptide_view_csv.php page is simple,it generates a CSV file using a header. header('Content-type: text/plain\n'); header('Content-Disposition: attachment; filename="peptide.csv"'); printf("everything i print out"); The problem is that after the user presses this button, but then wants to do something else on peptide_view.php, it automatically loads up the csv and displays that for the user to download. I'm pretty sure this is happening because the header information hasn't changed since the time he first pressed the peptide_csv button, but I don't know how to change this. When the user hits refresh on the page, it doesn't do this anymore, but is there a way to build it right into the page so that you can automatically perform other actions after you've pressed the peptide_csv button? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 14, 2007 Share Posted November 14, 2007 I assume you are setting the value of document.pressed with an onClick attribute of the buttons? I'm just wondering if the form's default action is peptide_view_csv.php and there's an issue with the change of form action. Quote Link to comment Share on other sites More sharing options...
ternto333 Posted November 14, 2007 Author Share Posted November 14, 2007 Yes, each button has an onclick="document.pressed=this.value" and the form has action = javascriptFunction() which is quoted above Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 14, 2007 Share Posted November 14, 2007 Yes, each button has an onclick="document.pressed=this.value" and the form has action = javascriptFunction() which is quoted above The action of your form shouldn't be the javascript function - it should be in the onClick attribute: e.g. onClick="return javascriptFunction();" Quote Link to comment Share on other sites More sharing options...
Mr P!nk Posted November 14, 2007 Share Posted November 14, 2007 if you have a few buttons in the form you could try this i use it and it works for me <script type="text/javascript"> function changeAction(ins) {var form1 = document.getElementById('buttons'); if(ins==0) form1.action = "thisfile.php"; if(ins==1) form1.action = "somefile.php"; if(ins==2) form1.action = "nicefile.php"; form1.submit(); } </script> to add more buttons to the .js just copy and paste the code and change the if(ins==#) accordingly and the button is like so <input type="submit" name="Submit1" onclick="changeAction(0)" value="Submit" /> <a href="#" onclick="changeAction(1)" target="_blank">Clicky Clicky</a> <input type="submit" name="Submit3" onclick="changeAction(2)" value="Submit" /> <input type="submit" name="Submit4" onclick="changeAction(3)" value="Submit" /> Quote Link to comment Share on other sites More sharing options...
ternto333 Posted November 14, 2007 Author Share Posted November 14, 2007 I didn't mean that the form had action="javascriptFunction" sorry, it has onSubmit="return javascriptFunciton();" It may not be the best way of doing it, but it works Quote Link to comment Share on other sites More sharing options...
ternto333 Posted November 14, 2007 Author Share Posted November 14, 2007 i have it set up like this, only imagine that one of your actions, "thisfile.php" goes to a page which allows a user to download a csv file. it works perfectly, but after it is done the header information is seemingly unchanged and in order to change buttons, you need to press the F5 key to refresh all the variables. if you have a few buttons in the form you could try this i use it and it works for me <script type="text/javascript"> function changeAction(ins) {var form1 = document.getElementById('buttons'); if(ins==0) form1.action = "thisfile.php"; if(ins==1) form1.action = "somefile.php"; if(ins==2) form1.action = "nicefile.php"; form1.submit(); } </script> to add more buttons to the .js just copy and paste the code and change the if(ins==#) accordingly and the button is like so <input type="submit" name="Submit1" onclick="changeAction(0)" value="Submit" /> <a href="#" onclick="changeAction(1)" target="_blank">Clicky Clicky</a> <input type="submit" name="Submit3" onclick="changeAction(2)" value="Submit" /> <input type="submit" name="Submit4" onclick="changeAction(3)" value="Submit" /> Quote Link to comment 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.