Catfish Posted December 19, 2009 Share Posted December 19, 2009 I am making a php script that will browse the contents of a mysql table and have pagination of the results. The scripts accepts a value for "results per page". I want this value to be user definable through the interface so I figured a text input box would suffice. I have run into a problem and not sure the best way to fix it. The browse script does a few things. It shows a pageful of results and creates page navigation links and the "result per page" input box, but I also want it to allow the user to select any number of records and then perform actions on them (edit, delete, export etc.) So my form is built something like: <html> <form> <input type="checkbox" name="data[]" value="$recordIDNum" /> <!-- etc. over and over for all records displayed and $recordIDNum varies --> <input type="submit" name="a" value="Edit" /><input type="submit" name="a" value="Delete" /> <!-- etc. for all actions that can be done --> <input type="text" name="resultsPerPage" value="$_SESSION['resultsPerPage']" /> </form> </html> Now... how my scripts work is based off the value of the 'a' variable. It will include() a php file for each action I create. So when I enter a value for results per page and press enter, it is using the submit button "Edit" so sets 'a' to "Edit" and then wants to include the php file for "Edit" which is wrong. I want it to leave 'a' as "Browse Table" and reload the browse page, with the new result per page value. Any hints? Quote Link to comment Share on other sites More sharing options...
Catfish Posted December 20, 2009 Author Share Posted December 20, 2009 Worked this one out eventually. Have to include a hidden <input> value for 'a' whose value is "Browse Table" (the action name I want when user changes results per page value). The <input> tag for the result per page value has to have an attribute called "onchange" with value "submit();" so: <form method="get" action="scriptname.php"> <input type="hidden" name="a" value="Browse Table" /> <input type="text" name="resultsPerPage" value="5" onchange="submit();" /> <!-- default value in box is 5 --> <input type="submit" name="a" value="Edit" /> <!-- etc. for other submit action values --> </form> When user changes the value of resultsPerPage, the page will reload using the hidden value of 'a' (Browse Table) instead of the first submit type input value (Edit). Without the onchange="submit();" attribute, the script uses the Edit action instead of the hidden value. 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.