Editing existing button function

I have been trying to edit a button from an open source web program to call on a php script I made. The original script creates a new window, calls on a php script to generate a barcode, places the barcode on the new window then causes the browser to print. My php script generates a raw file then calls on an exe to send it to a network printer. My php script works, I just cannot figure out how to edit the existing code to use my script without creating a new window.

Original related source:
[php]
// Setup Print Asset Tag button
protected function btnPrintAssetTag_Create() {
$this->btnPrintAssetTag = new QButton($this);
$this->btnPrintAssetTag->Text = QApplication::Translate(‘Print Asset Tag’);
$this->btnPrintAssetTag->AddAction(new QClickEvent(), new QAjaxControlAction($this, ‘btnPrintAssetTag_Click’));
$this->btnPrintAssetTag->AddAction(new QEnterKeyEvent(), new QAjaxControlAction($this, ‘btnPrintAssetTag_Click’));
$this->btnPrintAssetTag->AddAction(new QEnterKeyEvent(), new QTerminateAction());
$this->btnPrintAssetTag->CausesValidation = false;
}
// Print Asset Tag button Click Action
public function btnPrintAssetTag_Click($strFormId, $strControlId, $strParameter) {
$strImagePath = sprintf(’…/includes/php/barcode.php?code=%s&encoding=128&scale=1’, $this->objAsset->AssetCode);
QApplication::ExecuteJavaScript(‘var pwin = window.open("", “Image”);’);
QApplication::ExecuteJavaScript(sprintf(‘if (pwin) { pwin.document.writeln("<style type=“text/css”>body { margin:0; padding:0; } <img src="%s" />");pwin.document.close();pwin.focus();pwin.print(); }’, $strImagePath));
}
[/php]

My edit which works but has a popup window that I want to get rid of:
[php]
// Print Asset Tag button Click Action
public function btnPrintAssetTag_Click($strFormId, $strControlId, $strParameter) {
$strImagePath = sprintf(’…/includes/php/print.php?code=%s’, $this->objAsset->AssetCode);
QApplication::ExecuteJavaScript(‘var pwin = window.open("", “Image”);’);
QApplication::ExecuteJavaScript(sprintf(‘if (pwin) { pwin.document.writeln("<style type=“text/css”>body { margin:0; padding:0; } <img src="%s" />");pwin.document.close(); }’, $strImagePath));
}
[/php]

The full source of the file can be found at http://code.google.com/p/tracmor/source/browse/trunk/includes/qcodo/qform/QAssetEditComposite.class.php?spec=svn770&r=770

Any help would be greatly appreciated.

Well, first, you didn’t show and PHP code, so not sure about that. You should use # instead of PHP for your code when you show JAVASCRIPT. It is easier to know what is going on.

It sounds like you are attempting to call out to a PHP script and load the result back “DYNAMICALLY”.
If that is correct, one way is to use a hidden frame or even better a hidden iframe. This is basically
a second page inside your html page. You can load pages into it and read out the results. In this
way you can process the SERVER-SIDE PHP code in a page and load it into your current page for use
with your Javascript calls. You could load PHP page that creates the barcode into the hidden iframe.
This would be done in the PHP code as a simple or whatever.
Since the page loaded into the new hidden iframe would be an image, you can access it with your
javascript code in this manner: document.getElementById(‘iFrame1’).Image Of course, this is just
a starting point for you. I do this with drop-down lists that change options below it dynamically with
the screen not moving. Nice effect. Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service