On Sun, 28 Apr 2002 00:53:37 -0400, Jamie wrote:
> I Want to do something like below, but the SetupCitiesComboBox doesn't
> work as expected in the table. It displays a combo box before the table
> is constructed, NOT in it, but in the <td>block it just displays a 1.
> The SetupCitiesComboBox sub just adds cities to the menu_popip. If i
> change from a <select> to a CGI popup_menu would this work then?

It's a bit more difficult to determine what you want to do since you
didn't give the subroutines your program calls... but I'll take a stab.

The CGI.pm routines for generating HTML (table, TR, td, etc.) are 
methods of the CGI.pm object -- and can be called simply as functions, 
as you do here. Now, most of the documentation for CGI.pm shows examples
where you do something as follows:
 print h1("Some header");
and so we newbies get caught in a trap of thinking they can only be used
with print statements. And then we cannot figure out why things don't
print the way we want them.

I have gotten into a habit of using the functions to generate strings,
which I print out later. In this way, I can chain a whole page together,
and put in custom code if I want to, without worrying that my output
won't come in in the correct order. For example:
 $body  = h1("Some header");
 $body .= p("Some text in a paragraph",
            b("text done boldly"),
            i("text with italics"),
            "more plain text");
 $body .= table(
           TR(
            td("City: "),
            td("&SetupCitiesComboBox),
            td(""),
            td("")
           )
 );
etc., etc., etc. Then at the end you'd issue "print $body;".

What I suspect happened... see snippage below..
> 
> print table(
>     TR(
>       td("City: "),
>       td(&SetupCitiesComboBox),
&SetupCitiesComboBox contained a print statement creating a form with a
combo box. Since the current bit of code is still being interpreted for
its own print statement, the code in the SetupCitiesComboBox routine
actually gets printed first, as it finishes completion first.

>       td(" "),
>       td(" ")
>     )
> );
>       
> print "<TABLE>";
> print "<TR>";
> print "<TD>City:</TD>";
> print "<TD><select name=\"city\"><p>";
> 
> &AddCitiesToComboBox(@Cities);
This one prints correctly because it's NOT embedded within another print
statement.

> print "</select><P><P>";
> print "</TD>";
> print "<TD>";
> print "</TD>";
> print "<TD>";
> print "</TD>";
> print "</TR>"

--Matthew

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to