List Info

Thread: Re: having a html button/check box call a perl subroutine




Re: having a html button/check box call a perl subroutine
country flaguser name
United States
2007-07-25 10:35:09
Hi,
 
Thanks for your tips. This is actually similar to what I have right now. The problem with calling the same script again, that is, refreshing the entire page when the checkbox is clicked is that the checkbox is also refreshed which means it no longer appears to be clicked.
 
I was looking to do something where a person clicks 2 of the 4 checkboxes and only the image/graph changes. Then they unclick say one of the check boxes to see the image/graph change again. So they need to see what boxes are checked and what arent.
 
Do I think I can still do that somehow when refreshing the entire script?
 
thanks
dhivya
-----perl-win32-web-bounceslistserv.ActiveState.com wrote: -----

To: perl-win32-weblistserv.ActiveState.com
From: Lachlan <lashleyturing.une.edu.au>
Sent by: perl-win32-web-bounceslistserv.ActiveState.com
Date: 07/24/2007 10:50PM
Subject: Re: having a html button/check box call a perl subroutine

Firstly, have you looked into combining CSS with your javascript?
There are plenty of resources on the web that describe how to use the  
inline parameter to display and hide content.

You won't be able to run a perl sub after your page has been rendered  
unless you run your script again.
One of the most obvious ways is to refresh the page (ie. run the script  
again) when the checkbox is pressed.

I haven't done this with a checkbox but I have used a round-about way  
of getting a javascript action button to run a Perl sub.
I used a simple javascript action button. With the CGI module I used:

$cgiObject->;button(-name=>'nameofbutton',-value=>' Label of  
Button',-onClick=>"window.open('nameOfScript?
x=param1&amp;y=param2&z=param3'... )")

A javascript action button is displayed and when clicked opens a new  
window and goes to the address specified using the particular params.
One of the params is a flag to indicate a basic function mode for the  
script; basically which sub should be run (in the example 'x').

Towards the start of my script I have something like this ($qaz is the  
CGI object):

if (defined( $qaz->param('x') )){
 ; &nbsp; if ($qaz->param('x') eq 'value1'){
 &nbsp; &nbsp; ; &nbsp; runSub1();
&nbsp;   ;}
   if ($qaz->param('x') eq 'value2'){
 &nbsp; &nbsp; ; &nbsp; runSub2();
&nbsp;   ;}
   ...
}

You should be able to do something similar with a checkbox using  
onClick. Use the window.location.replace(x) function to reload the  
current page.
Of course, 'x' represents the script name with the parameter list. If  
you use the same sub to set the content and use the param list to alter  
what is set by that sub then code duplication is minimised - you don't  
need multiple subs to set up different page content if the 'page'  is  
practically the same.


Cheers,
Lachlan.


On 24 Jul 2007, at 7:02, Dhivya Arasappan/O/VCU wrote:

&gt; Hi everyone,
>  
>; I'm writing a perl program in which I'm setting up a html checkbox  
>; such that when it is clicked, a perl subroutine is called.
&gt;  
>; I know that I can call a javascript function when a checkbox is  
>; clicked in the following way:
>
> print "<input type='checkbox' name='check' value='checkbox'  
>; onClick='javascriptfn();'>";
>
> But how can I use the same checkbox to call a perl subroutine?
>
> Any kind of guidance would be really appreciated.
>
>; thanks
>;
> dhivya arasappan_______________________________________________
> Perl-Win32-Web mailing list
> Perl-Win32-Weblistserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Web mailing list
Perl-Win32-Weblistserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: having a html button/check box call a perl subroutine
country flaguser name
Australia
2007-07-25 23:05:40
I don't think it is possible to just run something in the
script without
refreshing the page (reloading the script), however knowing
the ingenuity
of full-time Perl hackers I would not be surprised if
someone has figured
out how to do something similar.

The controls from the CGI module uses what can be thought of
as sticky
values. The params from a form can be transferred to the
next form and be
set as values for the fields in a new page. For example; you
have a page
of checkboxes and a submit button. When a person clicks
'submit', the
values of the checkboxes are loaded into the param list and
is accessible
via $object->pram('name'). These values are not cleared
and CGI will
automagically set the values of checkboxes on the new page
with values in
the param list if they have the same name as the checkboxes
used in the
previous page.
This can be overridden by using
$object->delete_all()(clears the param
list) or setting the optional -override parameter in the
particular form
control to 1.

You could try out that method or you can sort of emulate it
with GET.
Emulating this action will depend on how many controls you
want to set
after reload. With this method you could add the required
values to keep
to the param list (with the URL that reloads the page). If
you have heaps
of values the param list at the end of the URL may become
unmanageable.

Therefore, the other way is to simulate a submit form action
so the CGI
module will do everything using POST instead of the previous
method that
uses GET to set param values.
For specific data values that are not actually controls, for
example the
function flag mentioned in my previous post, use a hidden
control and set
-value to the value you want.

This method is much simpler as the param values will be
virtually hidden,
unlike the previous method that requires the values to be
placed in the
param section of the URL.

Lachlan.


> Hi, Thanks for your tips. This is actually similar to
what I have right
> now. The problem with calling the same script again,
that is, refreshing
> the entire page when the checkbox is clicked is that
the checkbox is also
> refreshed which means it no longer appears to be
clicked. I was looking to
> do something where a person clicks 2 of the 4
checkboxes and only the
> image/graph changes. Then they unclick say one of the
check boxes to see
> the image/graph change again. So they need to see what
boxes are checked
> and what arent.  Do I think I can still do that somehow
when refreshing
> the entire script? thanksdhivya

_______________________________________________
Perl-Win32-Web mailing list
Perl-Win32-Weblistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )