COTPSoftwareToolsRadennxamdTecbntruresJorPrtAgdicaniokvedegxrsww.perl.comthe source for Perl福AdvancedPerlProgrammingMoreCGlProgrammingSinonSrinfshiyCOrRaily&AxtmesInc
More CGI Programming Software Tools
Lecture23/Slide2Checkbox and Link ExampleASimple Example-Netscape口口区File Edit View GoCommunicator HelpThe following exampleA合国NPriReloadHomeBackSearchNetscapeFnrardshows how to generateBookmarksWhat'sRelatedLocation~hornet/bill3.cg国NetcasteInstantMessage国IntermetLookupNew&CoolcheckboxesandlinksAA Simple ExamplewithyourCGlprogramWhat's your name?Checkboxes allow youWhat is Bill (check all that apply)?to select more than onegoodbadugly richfamous handsomeoption.一What is Bil'sfavorite color?lucky redThe initial screen isSubmit Queryshown on the rightGo to Homer's Homepage for HintsDocument:华国
Lecture 23 / Slide 2 Checkbox and Link Example The following example shows how to generate checkboxes and links with your CGI program. Checkboxes allow you to select more than one option. The initial screen is shown on the right
Lecture23/Slide3Checkbox and Link ExampleA Simple ExampleTheresult screen isshown on the rightWhat's your name? HornerNote that the outputWhat is Bill (check allthat apply)?information is displayedgoodbad ugly rich famous handsomebetween the originalWhat is Bil's favorite color? money greenform and the linkSubmitQueryYour name is: HornerBill is:bad, ughy,rich, famousBill'sfavoritecoloris:moneygreenGoto Horner's HomepageforHints
Lecture 23 / Slide 3 Checkbox and Link Example The result screen is shown on the right. Note that the output information is displayed between the original form and the link
Lecture23/Slide4Checkbox andLink Example pagel#!/usr/local/bin/perl5-w# simple example with checkbox and linkuse CGI qw(:standard);print header;Multi-lineprintprint start html("A simple Example")statementhl("A simple Example"),start form,"what's your name? ",textfield("name")p,pputsanew"what is Bill (check all that apply)?"paragraph/newlinep.checkbox group("words",[ qw(good bad ugly rich famous handsome)["rich","famous"]】whichboxestocheckP,"what is Bills favorite color? "asdefaultspopup_menu("color",["lucky red","money green","Microsoftblue"J)P,submit,"Submit Query used as defaultend form, hr;submit button name
Lecture 23 / Slide 4 #!/usr/local/bin/perl5 -w # Simple example with checkbox and link use CGI qw(:standard); print header; print start_html("A Simple Example"), h1("A Simple Example"), start_form, "What's your name? ",textfield("name"), p, "What is Bill (check all that apply)?", p, checkbox_group("words",[ qw(good bad ugly rich famous handsome) ], ["rich", "famous"]), p, "What is Bill's favorite color? ", popup_menu("color",["lucky red","money green","Microsoft blue"]), p, submit, end_form, hr; Checkbox and Link Example page1 Multi-line print statement p puts a new paragraph/newline which boxes to check as defaults “Submit Query” used as default submit button name
Lecture23/Slide5Checkbox andLink Example page2emgenerates<em>if(param())HTMLtag(-italics)print"Your name is: ",em(param("name")),P,"Billis:",em(join(",",param("words")))p,"Bill's favorite color is: ",em(param("color"))hr;"Go to Horner's Homepage for Hints");end html;printThecheckboxparameterisalistofcheckedboxesgeneratesHTML link
Lecture 23 / Slide 5 Checkbox and Link Example page2 if (param()) { print "Your name is: ",em(param("name")), p, "Bill is: ",em(join(", ",param("words"))), p, "Bill's favorite color is: ",em(param("color")), hr; } "Go to Horner's Homepage for Hints"); print end_html; em generates <em> HTML tag (~italics) The checkbox parameter is a list of checked boxes generates HTML link