in reply to Re: obtaining yyyy-mm-dd via a calendar object
in thread obtaining yyyy-mm-dd via a calendar object

Have a look at the CGI documentation, specifically the section on "CREATING THE HTML DOCUMENT HEADER".

The CGI header() function is used to generate a HTTP header, which relates to the communication protocol. You should not pass anything to it unless you know what it's for.

What you're looking for, then, is:

print header(), start_html( -script => $html1 );

Replies are listed 'Best First'.
Re^3: obtaining yyyy-mm-dd via a calendar object
by gmacfadden (Sexton) on Jul 31, 2006 at 00:37 UTC
    Your CPAN lead was helpful -thanks. FYI, the link http://home.netscape.com/eng/mozilla/2.0/handbook/javascript/ cited within the CPAN is defunct. Can you offer a viable url for the intended link?

    Based on this, here's where i'm at. let's take something a bit more simple to work out my kinks between Perl and Javascript (using what was in CPAN).

    a) it appears the javascipt must be put in-line with the Perl code as in the below code. I'd rather be able to keep the javascript separate if there is a way to do so...the major problem I see with this approach is the javascript source is printed out in it's entirety! It just clutters up the screen. So the first question, is how does one suppress the printout of the javascript?

    b) second question, i want to reference the variable 'answer' inside the javascript and place it in the form textfield 'answer'

    #! /usr/bin/perl -wT use CGI qw(:standard escapeHTML); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; print header (), my $JSCRIPT=<<END; // Ask a silly question function riddle_me_this() { var r = prompt("What walks on four legs in the morning, " + "two legs in the afternoon, " + "and three legs in the evening?"); response(r); } // Get a silly answer function response(answer) { if (answer == "man") alert("Right you are!"); else alert("Wrong! Guess again."); } END print start_html(-title=>'The Riddle of the Sphinx', -script=>$JSCRIPT); print p ("Element names & values submitted in previous form:"); my @names = param (); # get list of parameter names if (!@names) { print p ("(no elements present)"); } else { my @item = (); foreach my $name (@names) { my @val = param ($name); $val[0] = "[" . join (", ", @val) . "]" if @val > 1; push (@item, escapeHTML ("$name: ($val[0])\n")); } print ul (li (\@item)); } print hr (); print start_form (-action => url ()), p ("Enter riddle answer:", textfield (-name =>"answer", -id=>'response +1' -type=>"text", -size=>"30"), button(-name=>'riddle_button', -valu +e=>'Ask A Riddle', -onClick=>"riddle_me_this(response1)")), br(), p ("Enter your name:", textfield (-name =>"name", -type=>"text", -size +=>"30")), br(), submit (-name => "Submit Button", -value => "Submit"), reset (-name => "Reset Button", -value => "Reset"), end_form (); print end_html (); exit (0);
      I'd rather be able to keep the javascript separate if there is a way to do so...

      You can always generate it as a separate file, and link it into your HTML. Also, Perl has a number of Templating modules, such as HTML::Template and Template Toolkit, which are designed to cleanly pull the HTML (and, by extension, Javascript embedded in HTML and/or "pure" Javascript files) formatting out of your Perl code.

      *EDIT because I forgot to put this back in* To reference the answer from the Javascript in the HTML you're creating, you'll need, ironically, to set the Value of the textfield to equal the value of the Javascript -- although there are other ways, this might be the cleanest. You would do something like document.getElementById("response1”).value = "text_of_answer" to set it, and you can put it where you need to within the Javascript itself.

      Having said that...if you're unfamiliar with Javascript, you're likely best to do some research and testing with static files containing HTML and Javascript, and then come back to implementing CGI. Even if your values are from CGI forms, you can just use a test variable and roll with it.

      You're trying to cover a LOT of newtech in one go, and I think, from reading your past writeups, this might be causing you frustration. Take one chuck of tech (HTML, Javascript, Perl, etc.) at a time, play with them, and you should find great success!

      *Another minute, another EDIT...* Try the new Mozilla Javascript site -- it's basically the replacement for the site in the CGI docs you found was dead.

      Goes off to check into making a small patch to the CGI.pm docs...

      ----Asim, known to some as Woodrow.

        Thanks for your suggestions (and everyone else's helpfulness) - they offered several teachable experiences in better understanding HTML, javascript, and GCI.
        When i read in the CPAN CGI documentation that the javascript action button will probably not even display on non-netscapre browsers, i realized it was time to quit and plan another way to attack my problem.
        I came across a great website for example code, www.krugle.com. Their section on GIMP Toolkit (GTK), using perl seems pretty extensive. Before i spend the same amount of time digging down into GTK calendar widgets and the like, would welcome other's opinion as to the usefulness of this site, and any suggestions as to my long ago simple goal (from perl, to click on an calendar object to select a date, and fill in a form variable with the selected date).
        net-net, will i be on a fruitful path if i go done the TDK calendar widget route?