/    Sign up×
Community /Pin to ProfileBookmark

Window.print()

Hello,

I want simply add a record in the database each time the user click print , do you have any idea how I can do that, my problem now how I can pass a variable from onclick so I can use it in this PHP code

if ($_GET[‘formVar’] == ‘on’) {
$Option = 15;
include ‘counters.php’;
}

Thanks for your HELP HELP HELP

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordJul 14.2008 — you could pass all you parms in the onclick or action methods of the button
Copy linkTweet thisAlerts:
@usm2000authorJul 14.2008 — Here what I wrote

echo <<<EOF

<table class="noprint">

<tr>

<td> <a href="#" onclick="document.formVar.value='on';return false;window.print()"><img src="../print.gif" border="0" id="print-button"> Print </a>&nbsp; &nbsp;</td>

</tr>

</table>

EOF;



**********

but it's not working
Copy linkTweet thisAlerts:
@SyCoJul 15.2008 — There are 2 ways to do this, the first is to have the print button submit a form. You could open a new window that does the database update or set the action to an iframe (height 0, width 0) or of course have the whole page.

The other way is to use ajax the onclick would pass the vars to PHP via ajax and do the update and send the print() command back.

I use xajax and knew next to nothing about ajax when I started. Once the page is set to use xajax it's really easy.

Look at the the 10 minute tutorial on http://xajaxproject.org/wiki/Tutorials

[code=php]
<?
require("xajax.inc.php");
$xajax = new xajax();

function printtrack() {
$objResponse = new xajaxResponse();
mysql_query("UPDATE table WHERE WHATEVER");
$objResponse ->addScript('window.print()');
return $objResponse;
}
$xajax->registerFunction("printtrack");

$xajax->processRequests();

?>
<html>
<head>
<?php $xajax->printJavascript(); ?>
</head>
<body>
<a href="#" onclick="xajax_printtrack()" return false;>Print page</a>
</body>
</html>[/code]


with xajax it's very easy to do all sorts of cool stuff that previously required a decent javascript knowledge. I'm a big fan ?
Copy linkTweet thisAlerts:
@usm2000authorJul 15.2008 — Ok I used iframe, but still not recording in the database

[U]here's the Javascript function[/U]

" <script type="text/javascript">n".
" function callIframe()n".
"{n".
" var rFrame = document.getElementById("ifrPrint");n".
" window.print();n".
"}n".
"</script>n".



***********************
[U]here's the iframe[/U]

echo "<IFRAME src="counters.php/?$mOption = 15;" scrolling="no" width="0" height="0" frameborder="0" name="ifrPrint" id="ifrPrint"></IFRAME>";


***************

[U]here's the onclick event[/U]


echo <<<EOF

<table class="noprint">

<tr>

<td> <a href="#" onclick="callIframe()"><img src="../print.gif" border="0" id="print-button"> Print </a>&nbsp; &nbsp;</td>

</tr>

</table>

EOF;


************

There's one more thing I pass a variable within iframe is it ok??
Copy linkTweet thisAlerts:
@felgallJul 16.2008 — There is no way to capture if someone just hits their browser print button which is the most obvious way that people will try to print your page.
Copy linkTweet thisAlerts:
@rm_webdeveloperJul 16.2008 — Hello,

I want simply add a record in the database each time the user click print , do you have any idea how I can do that, my problem now how I can pass a variable from onclick so I can use it in this PHP code


if ($_GET['formVar'] == 'on') {

$Option = 15;

include 'counters.php';

}

Thanks for your HELP HELP HELP[/QUOTE]


[CODE]

<?php
function myfunction(){
global $click;
$str = <<<RMDEV
<input style="background-color: rgb(255, 255, 160);" name="BankOthers" value="" class="" maxlength="25" id="" type="text" size="30">
RMDEV;
echo $str;
}
if (isset($execute) ){
myfunction();
}

?>
<html>
<head></head>
<title></title>
<body>
<a href="<?php echo("$PHP_SELF?execute=myfunction")?>">RUN AND CHANGE THIS FUNCTION</a>
</body>
</html>
[/CODE]


try this! change the myfunction on adding records to database.
×

Success!

Help @usm2000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...