CGI プログラム13

戻る

#!C:/perl/bin/perl # select_start.pl # 07.11.27 use strict; use HTML::Template; my (%t,@loop,$n); # ループデータ生成 @loop = (); for $n ( 1 .. 100 ) { my %row = ( NO => $n ); # put this row into the loop by reference push(@loop, \%row); } # HTMLファイル出力 $t{template} = HTML::Template->new(filename => 'select_start.htm'); $t{template}->param(LOOP => \@loop); print $t{template}->output; 1; ------------------------------------------------------------------------------- <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <head><title>select_start</title> <head> <body bgcolor="#fcf5ca"> <h2>select_start</h2> <a href="http://localhost/index.html">http://localhost/index.html</a> <hr> <form method="POST" action="select_show.pl"> 数量を選択し,「選択」をおしてください。<br> QTY==> <select name="SEL1"> <TMPL_LOOP NAME="LOOP"> <option value="<TMPL_VAR NAME="NO">"><TMPL_VAR NAME="NO"></option> </TMPL_LOOP> </select> <hr> 100を超えた場合,入力してください。<br> <div>QTY==><input type="text" name="SEL2"></div> <input type="submit" value="選択"> <input type="reset" value="取消"> </form> <hr> </body> </html> ------------------------------------------------------------------------------- #!C:/perl/bin/perl # select_show.pl # 07.11.27 use strict; use CGI qw/:standard/; use HTML::Template; my (%t); # CGIのパラメータ転送 $t{q} = new CGI; $t{select1} = $t{q}->param("SEL1"); $t{select2} = $t{q}->param("SEL2"); # 2つのデータを選別 if ($t{select2} =~ /\d*/ and $t{select2} > 100 ) { $t{select} = $t{select2}; } else { $t{select} = $t{select1}; } # HTMLファイル出力 $t{template} = HTML::Template->new(filename => 'select_show.htm'); $t{template}->param(select => $t{select}); $t{template}->param(select1 => $t{select1}); $t{template}->param(select2 => $t{select2}); print $t{template}->output; 1; ------------------------------------------------------------------------------- <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <head><title>select_show</title> <head> <body bgcolor="#fcf5ca"> <h2>select_show</h2> <a href="http://localhost/index.html">http://localhost/index.html</a> <hr> 選択結果は次のとおりである。<br> select==><TMPL_VAR NAME="select"><br> select1==><TMPL_VAR NAME="select1"><br> select2==><TMPL_VAR NAME="select2"><br> <hr> <a href="http://localhost/scripts/select_start.pl">戻る</a> </body> </html> -------------------------------------------------------------------------------
戻る