Voodoo Jai Posted October 9, 2008 Share Posted October 9, 2008 I want to pass a dynamic value into a confirm button so I get the correct form value. The form uses this script <script type="text/javascript"> function go_there() { var r=confirm("Printing a receipt confirms the payment has been received!" + '\n' + " PRINT A RECEIPT!"); if (r==true) { window.location="http://localhost/mark-paid.php?PaperworkID=<?php echo $row_PreviousInvoices['PaperworkID']; ?>&ID=<?php echo $row_Recordset1['TakeawayID']; ?>"; } } </script> and this to start it <FORM> <INPUT TYPE="button" value="Print a receipt!" onClick="go_there()"> </FORM> I want to pass a dynamic piece of data into the input button that is then used in the script. Something like this <FORM> <INPUT TYPE="button" value="Print a receipt!" onClick="go_there(<?php echo $row_PreviousInvoices['PaperworkID']; ?>)"> </FORM> which is then used in the script like <script type="text/javascript"> function go_there($DYNAMIC_DATA) { var r=confirm("Printing a receipt confirms the payment has been received!" + '\n' + " PRINT A RECEIPT!"); if (r==true) { window.location="http://localhost/mark-paid.php?PaperworkID=$DYNAMIC_DATA&ID=<?php echo $row_Recordset1['TakeawayID']; ?>"; } } </script> I have highlited the DYNAMIC_DATA in lime green to show you how and what I want to pass. Basically can I pass a variable into the confirm submit button and the pass this into the next page for use. Complicated but many thanks in advance VoodooJai Quote Link to comment https://forums.phpfreaks.com/topic/127699-solved-problem-passing-dynamic-data-into-a-confirm-button/ Share on other sites More sharing options...
genericnumber1 Posted October 9, 2008 Share Posted October 9, 2008 it's easiest to pass a variable between pages in a hidden input field. <input type="hidden" name="PaperworkID" value="<?php echo $row_PreviousInvoices['PaperworkID']; ?>" /> <input type="hidden" name="ID" value="<?php echo $row_Recordset1['TakeawayID']; ?>" /> or something like that don't forget you still need to verify these passed values even though they were hidden to the user. They're unclean and can be changed by a malicious user using a special browser plugin, their own form, a script, etc. If you want to be 100% sure the user can't change the values you'll need to use sessions, which is a whole 'nother beast. Quote Link to comment https://forums.phpfreaks.com/topic/127699-solved-problem-passing-dynamic-data-into-a-confirm-button/#findComment-660908 Share on other sites More sharing options...
Brandon Jaeger Posted October 9, 2008 Share Posted October 9, 2008 As for the JS, I think this will work (I'm not much of a JS programmer, but I know a couple of things): <script type="text/javascript"> function go_there(data) { var r=confirm("Printing a receipt confirms the payment has been received!" + '\n' + " PRINT A RECEIPT!"); if (r==true) { window.location="http://localhost/mark-paid.php?PaperworkID=" + data + "&ID=<?php echo $row_Recordset1['TakeawayID']; ?>"; } } </script> Quote Link to comment https://forums.phpfreaks.com/topic/127699-solved-problem-passing-dynamic-data-into-a-confirm-button/#findComment-660912 Share on other sites More sharing options...
Voodoo Jai Posted October 9, 2008 Author Share Posted October 9, 2008 As for the JS, I think this will work (I'm not much of a JS programmer, but I know a couple of things): <script type="text/javascript"> function go_there(data) { var r=confirm("Printing a receipt confirms the payment has been received!" + '\n' + " PRINT A RECEIPT!"); if (r==true) { window.location="http://localhost/mark-paid.php?PaperworkID=" + data + "&ID=<?php echo $row_Recordset1['TakeawayID']; ?>"; } } </script> Many thanks yes that works great I just coould not figure out ho to write it, thanks again. Also the pages are for restricted users so should I still clense them, if so what should I be doing. Quote Link to comment https://forums.phpfreaks.com/topic/127699-solved-problem-passing-dynamic-data-into-a-confirm-button/#findComment-660926 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.