Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi Monks,

I have 3 different report output options in a web browser (csv download, screen display, and pdf), but after displaying the report, I'd like the server to send some javascript to the browser that calls my javascript function showWait(0); which closes my "Please wait" window.

<script> function getReport3(){ showWait(1); if(document.getElementById('outputTypeScreen').checked){ document.reports.setAttribute("target", 'report_window +'); var'','report_window','scrollbars +=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status= +no'); }else{document.reports.setAttribute('target','_self');} document.reports.submit(); } </script> ... <form method="post" id='reports' name='reports'> <input type='hidden' name='rm' value='reports_getReport'> ... <input type='radio' name='outputType' id='outputTypeDownload' value='d +ownload'><label for='outputTypeDownload'>CSV Download</label> <input type='radio' name='outputType' id='outputTypeScreen' value='scr +een' ><label for='outputTypeScreen'>Screen</label> <input type='radio' name='outputType' id='outputTypePDF' value='pdf' > +<label for='outputTypePDF'>PDF</label> <input type='button' value='Search' onclick='getReport3()' > </form>
Server code:

use CGI ':standard'; use CGI ':cgi-lib'; use CGI::Carp qw(fatalsToBrowser); use Switch; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use Template; use Template::Stash; use strict; use warnings; ... sub reports_getReport{ my $self = shift; my $q = $self->query; ... switch($outputType){ case 'download'{ my $data=csvReport($report); #take the data and convert to com +ma delimited $self->header_props(-type => 'application/octet-stream +', -attachment => 'report.csv'); $self->header_add(-script=>{-type=>'text/javascript',-code=>' +alert("hi there"); showWait(0); '}); return $data; } case 'screen'{#this works!!! my $html=screenReport($report); return $html; } case 'pdf'{ my $data=getReport($report);#$data is a pdf stream $self->header_props(-type => 'application/pdf', -attac +hment => 'report.pdf'); $self->header_add(-script=>{-type=>'text/javascript',-code=>' +alert("hi there"); showWait(0); '}); return $data; } else{} } } sub screenReport{ my $report=shift; my $html=''; $html.=' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns="" lang="en-US" xml:lang="en-U +S"> <head> <script type="text/javascript" src="/forms/layout/sorttable.js"></scri +pt> <script type="text/javascript">var opener=this.window.opener; +owWait(0);</script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body>'; ... $html.='</body></html>'; return $html; }

My 'screen' case works fine, but I'm not able to get my 'download' and 'pdf' cases to run any javascript. Otherwise, everything works like they're supposed to. Is this even possible?

In reply to CGI attachment + javascript? by ksublondie

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [LanX]: "DH" eq "Dumb Homies "?
    [shmem]: no, no previous, and python just accepts that.
    [LanX]: HA ... fun! =)

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (13)
    As of 2018-03-20 18:24 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (257 votes). Check out past polls.