Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

changing title of a webpage dynamically

by tejas (Initiate)
on Jun 04, 2013 at 18:48 UTC ( #1037038=perlquestion: print w/ replies, xml ) Need Help??
tejas has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys,

Have been trying to learn cgi and perl since a couple of days. and have been stuck here...

I would like to change the title and contents of table using buttons but have no clue how to proceed.

this is my code so far...

I want the tomorrow and yesterday buttons to change the table and set title button to set the title... can anyone point out how i should proceed??

#!/usr/bin/perl -w use CGI qw(:all) ; my $today; my $thismonth; my $thisyear; chomp($today = `date +"%-d"`); chomp($thismonth = `date +"%-m"`); chomp($thisyear = `date +"%Y"`); $cgi = CGI->new; print $cgi->header,$cgi->start_html("$today.$thismonth.$thisyear"); print<<HTML; <table border=1> <tr> <td><button type="button" onclick="dont know what to put here">Yes +terday</td> <td>$today</td> <td>$thismonth</td> <td>$thisyear</td> <td><button type="button" onclick="dont know what to put here">Tom +orrow</td> <td><button type="button" onclick="dont know what to put here">Set + Title</td> </tr> </table> HTML print $cgi->end_html;

Comment on changing title of a webpage dynamically
Download Code
Re: changing title of a webpage dynamically
by toolic (Chancellor) on Jun 04, 2013 at 18:56 UTC

      ya i am a newbie but not a complete one.... have gone through some documents but couldn't find how to do this bit...

      What i mean to say is all the examples i have seen so far collect the info from a form and print the details at the bottom of the page or in a file. I haven't seen a any example that that itself and that's what i want to do here...

Re: changing title of a webpage dynamically
by bart (Canon) on Jun 04, 2013 at 19:49 UTC
    What you seem to be wanting is a way to pass a date as a parameter, and use today only as a default. Or, pass a relative day offset, with 0 for today, -1 for yesterday and 1 for tomorrow, for example.

    It might be helpful if you didn't depend on the external program date to get the dateparts. Perl is perfectly capable of handling those dateparts itself, either on its own, or via simple, standard modules, or via more elaborate CPAN modules (and that's just one example). The latter can be used for relative date calculations; on the latter you can get by calculating the times in seconds, but watch out for summer time, and thus days that are not 24 hours long. Calculating days relative to noon, on any day, is safe.

    To pass around the values, you need form variables (thus a HTML form, or equivalent), and form values processing on the server side, either via GET or POST; CGI.pm, which you are already using, will do fine.

    For the form values, you can use any button to set a hidden input using Javascript before submitting the form; or you can use ordinary links, where you convert the parameter values straight to an URL. (Ordinary <input name="d" value="x" type="submit"> isn't usable because of the mixup in HTML between the value in the form and the text on the button.)

    I could elaborate and give examples on all approaches, but just one solution is enough so you'd better let us know which approach you're thinking on taking.

      I am not particularly interested in the dates so I just used what I was most familiar with...

      The form method would be fine is guess but i have no knowledge of javascript. But I guess any simple solution will do

      I think i get the point of using internal modules so that we can get absolute offset... but I guess I was thinking more in terms of relative offset... like whats in table +1 or whats in table -1...

Re: changing title of a webpage dynamically (javascript)
by Anonymous Monk on Jun 04, 2013 at 23:56 UTC
Re: changing title of a webpage dynamically
by sundialsvc4 (Monsignor) on Jun 05, 2013 at 00:05 UTC

    If you want to change the title “and such” using buttons, then it is extremely probable that you will need to use JavaScript to do that.

    You see, the only time that the server (i.e. Perl) would become involved, is when there is a “round-trip” involved:   the client makes an HTTP GET or POST to the server, and server replies with an HTTP response.

    Most likely, everything that you want to happen ... happens entirely on the client side, start to finish.   As the most-simple example, the button could contain a onclick= handler which runs a bit of JavaScript code that changes, say, the window.title (in the browser’s own DOM model).   When the JavaScript code does that, the browser obediently repaints the screen.   The server, meanwhile, has nothing to do with it.

      i just had an idea but not sure if it is practical...

      but can i call a cgi script recursively from itself??? is it possible to do that???

        Ok guys i think i have found one solution to my problem :D

        i called my own scribt back again. i have done it for only i button but it seems to be working :D

        the link http://www.cgi101.com/learn/ given by toolic helped me, thanks.

        so any other solutions apart from this one??

        #!/usr/bin/perl -w use CGI qw(:all) ; my $today; my $thismonth; my $thisyear; chomp($today = `date +"%-d"`); chomp($thismonth = `date +"%-m"`); chomp($thisyear = `date +"%Y"`); my $cal; my $dir; $cgi = CGI->new; $dir=$cgi->param("dir"); if($cgi->param("today") && $cgi->param("thismonth") && $cgi->param("th +isyear")) { if($dir eq "back") { $today=$cgi->param("today"); $today=$today-1; } } print $cgi->header,$cgi->start_html("$today.$thismonth.$thisyear"); print<<HTML; <table border=1> <tr> <td><form name="input" action="date.cgi" method="POST"> <input type="hidden" name="today" value="$today"> <input type="hidden" name="thismonth" value="$thismonth"> <input type="hidden" name="thisyear" value="$thisyear"> <input type="hidden" name="dir" value="back"> <input type="submit" value="Yesterday"></td> </form> <td>$today</td> <td>$thismonth</td> <td>$thisyear</td> <td><button type="button">Tomorrow</td> <td><button type="button">Set Title</td> </tr> </table> HTML print $cgi->end_html;
Re: changing title of a webpage dynamically ( Mojolicious::Lite Time::Piece )
by Anonymous Monk on Jun 07, 2013 at 08:36 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1037038]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (14)
As of 2014-08-28 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (261 votes), past polls