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

i'm trying to print an option box but when it prints it just prints all the values out in a line instead of printing the option box structure. the code is
print "<table border=1> \n"; print "<tr>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"9%\">image3</td>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"9%\">&nbsp;</td>\n"; print "<td width=\"10%\">&nbsp;</td>\n"; print "</tr>\n"; print "<tr>\n"; print "<td width=\"9%\"><b><P align=center><SELECT name=Team6 size=1>\ +n"; print "<OPTION selected>$list_of_teamdata[5][1]</OPTION>\n"; print "<OPTION>Business School</OPTION>\n"; print "<OPTION>Admin/Estates</OPTION>\n"; print "<OPTION>CEAC </OPTION>\n"; print "<OPTION>Civ Eng</OPTION>\n"; print "<OPTION>Combined Honours</OPTION>\n"; print "<OPTION>CSAM</OPTION>\n"; print "<OPTION>EEAP</OPTION>\n"; print "<OPTION>MechEng</OPTION>\n"; print "<OPTION>ModLang</OPTION>\n"; print "<OPTION>Vision Sciences</OPTION>\n"; print "<OPTION>Pharmacy</OPTION>\n"; print "&nbsp;</SELECT>\n"; print "</P>\n"; print "</td>\n"; print "</b>\n"; print "<td width=\"9%\"><b><P align=center><SELECT name=score6 size=1> +\n"; print "<OPTION selected value>$list_of_teamdata[5][2]</OPTION>\n"; print "<OPTION>0</OPTION>\n"; print "<OPTION>1</OPTION>\n"; print "<OPTION>2</OPTION>\n"; print "<OPTION>3</OPTION>\n"; print "<OPTION>4</OPTION>\n"; print "<OPTION>5</OPTION>\n"; print "<OPTION>6</OPTION>\n"; print "<OPTION>7</OPTION>\n"; print "<OPTION>8</OPTION>\n"; print "<OPTION>9</OPTION>\n"; print "<OPTION>10</OPTION>\n"; print "<OPTION>11</OPTION>\n"; print "<OPTION>12</OPTION>\n"; print "&nbsp;</SELECT>\n"; print "</P>\n"; print "</td>\n"; etc
i know the print statements aren't pretty but i just want to be able to design an html doc and put it into code. can u see any errors??

Replies are listed 'Best First'.
Re: html print out problems
by arturo (Vicar) on Apr 03, 2001 at 19:49 UTC

    When HTML isn't done according to spec (and often when it is), how it's displayed in a browser depends on which browser you're using. My suspicion is that you're missing some sort of tag in here.

    One thing that might be going wrong is that you don't have a <form> tag in your code anywhere (there's none in what you've posted). At any rate, the problem is *probably* not in the code you've posted, but somewhere else.

    As for your methods ... well, you could turn it into a here document, but the popular CGI module makes generating option lists very simple for you. Here's some code that will produce your second list, nice n' easy.

    use CGI; my $q = CGI->new(); my @options = 1..12; print $q->scrolling_list(-name=>"score6", -values=>\@options, -size=>1 );

    HTH

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

(jeffa) Re: html print out problems
by jeffa (Bishop) on Apr 03, 2001 at 20:01 UTC
    arturo beat me to the punch, but I want to show you this anyway:
    use strict; use CGI qw(:standard :html3); my @teamdata = qw(Business CEAC CSAM MechEng Pharmacy); my @teamnums = (0..12); print header, start_html('Some Form'), start_form, table({-border=>undef}, caption('Some Form'), Tr({-align=>CENTER,-valign=>TOP}, [ th([qw(Data Numbers)]), td( [ popup_menu('data',\@teamdata), popup_menu('nums',\@teamnums), ]), ]), ), end_form, end_html;
    Use CGI - makes your code pretty and more important, maintainable!

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
Re: html print out problems
by physi (Friar) on Apr 03, 2001 at 19:42 UTC
    If you want to parse this to your browser, don't forget to add
    print "Content-type: text/html\n\n";
    at the top of your script :^)
    ----------------------------------- --the good, the bad and the physi-- -----------------------------------
Re: html print out problems
by jbwiv (Acolyte) on Apr 03, 2001 at 21:19 UTC
    If you're viewing the code in Netscape...

    Netscape will not *correctly* display form elements (option boxes, text boxes, etc) unless you enclose the tags within a form tag.

    IE, however, will display them regardless.

    jbwiv