Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I apologise if this question is more directed at HTML/Javascript coding. How can I create a condition that if an image is clicked from within a page, it will cause an event to generate a particular piece of code. I have a piece of code that generates an output to excel using Win::OLE. I only want this to occur when a image is clicked and to not change the state of the current page (eg not post to another script). Another learning curve for me to over come. Thankyou to anyone willing to offer any help.
  • Comment on OT: Running Event after ClickOn browser event

Replies are listed 'Best First'.
Re: CGI programming
by Your Mother (Archbishop) on Sep 08, 2004 at 04:03 UTC
    ...it will cause an event to generate a particular piece of code...

    That's a little vague but this might be enough to get you started. It's JS but the use of Perl often involves sidebars like JS and SQL.

    <script type="text/javascript"> function postToApp () { alert('Generating code... Or opening a CGI with args... or...') return false } document.write('<img src="" style="border:1px solid ') document.write('black;width:80px;height:100px;" ') document.write('onclick="postToApp()" ') document.write('alt="no source!" />') </script> <noscript> Special functions are reserved for those less paranoid. Enable JavaScript in your browser to use this. </noscript>
    The Rhino and The Howler Monkey are both good investments, of course.

Re: CGI programming
by japhy (Canon) on Sep 08, 2004 at 02:56 UTC
    If you don't want clicking a link to change the page, your program should return a "204 No Content" response.
    _____________________________________________________
    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: CGI programming
by chanio (Priest) on Sep 09, 2004 at 00:45 UTC
    It has to do with perl, yes.

    The main thing is telling the browser that nothing has happened after clicking the image (button).

    In fact, the server did load your cgi script that called your excel thing. But you need to tell the browser that the screen is not going to update with anything. So, it is all going to look the same as before clicking.

    So, use CGI; and send the following header after leaving your cgi script...

    print $cgi->header( -status=>'204 No Response', -expires=>'+3d', ) if ($ENV{HTTP_REFERER});
    Good luck!

    .{\('v')/}
    _`(___)' __________________________