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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.