Jump to content

[SOLVED] Problem passing dynamic data into a confirm button


Voodoo Jai

Recommended Posts

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

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.

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>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.