revTalk CGI 05: クリックでイメージを書き出す
バリエーション:クリックした文字列の真偽を GET で受ける
表示サンプル
文字列をクリックして該当するイメージファイルを表示させるスクリプトです。
イメージをブラウザーに表示させるのは、例えば
<img src="../Photo/GreatLawn/mosaic/Great-Lawn-001.jpg" width="640" height="480" border="0">
のようになりますから、
文字列をクリックすると該当するイメージの URL が、「src=」の後に記述されれば良いわけです。
「03 クリックした文字列の真偽を GET で受ける」の、クリックするスクリプトは以下のようになっています。
<a href="rev03_urlGet.irev?variable1=true">Click Variable1</a><br />
ここでは受け取るページのファイル名「rev05_selectImage.irev」と、
$_GET で受ける値を「001」に書き換えます。
<a href="rev05_selectImage.irev?001=true">Image 001</a>
この文字列「Image 001」をクリックすると、
$_GET["001"] は「true」を返します。
さらに the keys of $_GET は「001」を返しますから、
その値を利用してイメージソースを書き進めて行きます。
<?rev
-- the keys of $_GET で得る値をパラメータとして、イメージソースを作るファンクション--
function imageSrc pImage
return "<img src='../Photo/GreatLawn/mosaic/Great-Lawn-" & pImage & \
".jpg' width='640' height='480' border='0'>"
end imageSrc
?>
<body>
<a href="rev05_selectImage.irev?001=true">Image 001</a><br />
<a href="rev05_selectImage.irev?002=true">Image 002</a><br />
<a href="rev05_selectImage.irev?003=true">Image 003</a><br /><br />
<?rev
-- the keys of $_GET が empty でなければ、イメージ名とイメージを表示 --
if the keys of $_GET <> empty then
put "Image " & the keys of $_GET &"<br \>"
put imageSrc(the keys of $_GET)
end if
?>
</body>