PDA

View Full Version : Setting a listbox to a variable


briintex1
11-10-2005, 05:10 PM
I am new to pearl, and might be getting in to deep. But I was wondering if I have a listbox say something like this


<table align = left>
<select name="select1" size="5" length="3">
<option VALUE="choice1" SELECTED><a href="query.cgi"><li id="query">this</a></li>
<option VALUE="choice2" SELECTED><li id="enter-bug"><a href="enter_bug.cgi">that</a></li>
<option VALUE="choice3" SELECTED><li id="report"><a href="report.cgi">these</a></li><form name="login" action="/index.cgi" method="POST">
<option Value="choice4" SELECTED><li id="account"><a href="createaccount.cgi">those</a></li>
<select>
</table>


and I want to set the item that is selected to goto another page. So for instance
if someone clicks the first choice "This" it takes them to another page, and the same thing should be done for the other choices in the list box. Can this be done with Pearl, if so can someone help me?

THanks
bri

TheShaner
11-10-2005, 05:29 PM
yourpage.html
<form name="login" action="index.cgi" method="POST">
<select name="select1" size="4">
<option value="choice1">this</option>
<option value="choice2">that</option>
<option value="choice3">these</option>
<option value="choice4">those</option>
</select>
<input type="submit" value="Submit">
</form>
index.cgi (assuming you're using the CGI module)
if (param('select1') eq "choice1")
{
print redirect("query.cgi");
}
else if (param('select1') eq "choice2")
{
print redirect("enter_bug.cgi");
}
else if (param('select1') eq "choice3")
{
print redirect("report.cgi");
}
else if (param('select1') eq "choice4")
{
print redirect("createaccount.cgi");
}
else
{
print redirect("yourpage.html");
}
-Shane

FishMonger
11-10-2005, 06:01 PM
use Switch;

switch (param('select1')) {
case "choice1" { print redirect("query.cgi") }
case "choice2" { print redirect("enter_bug.cgi") }
case "choice3" { print redirect("report.cgi") }
case "choice4" { print redirect("query.cgi") }
}
Or
%select1 = (
"choice1" => "query.cgi",
"choice2" => "enter_bug.cgi",
"choice3" => "report.cgi",
"choice4" => "query.cgi",
);

print redirect($select1{param('select1')});