开发者

HOW to do - click on submit button opens hyperlink with parameter from option in perl cgi

On a CGI page(opened from index.html), this is the sample code ->

while (@row = $sth2->fetchrow_array()) {  # retrieve one row
print <<eoh1;    
    <option value=$row[0]>$row[0]</option> #Say it fills option values 1,2,3
eoh1
 }

print <<eoh2;
<input type="submit" name="get" value="Go">
 </select>
eoh2

Now from drop-down, user selects 2, so it should open www.xyz.com/2 in a new window.

Plz help...i m a novice in perl cgi and need 开发者_如何学运维to submit this asap :(


Given that the value of the selected option is the url in question you could do something like this:

<form onsubmit="open(this.url.value,'','');return false;">
<select name="url">
<option value ="http://url1">1</option>
<option value ="http://url2">2</option>
<option value ="http://url3">3</option>
</select>
<input type="submit" name="get" value="Go">
</form>

you can see it running here: http://jsfiddle.net/Fgk7s/


The following is a solution that does not use Javascript. Using Javascript might give you other options.

You need to write another script that is the action target of your form:

print <<eoh0;
<form name="myForm" action="otherScript.pl" type="get" target="_blank">
<select name="mySelect" id="mySelect">
eoh0

while (@row = $sth2->fetchrow_array()) {  # retrieve one row
print <<eoh1;    
    <option value="$row[0]">$row[0]</option> #Say it fills option values 1,2,3
eoh1
 }

print <<eoh2;
 </select>
<input type="submit" name="get" value="Go">
</form>
eoh2

In otherScript.pl, you use CGI to get your arguments.

use CGI;

my $co = new cGI;
my $arg = co->param("mySelect");

$co->redirect("/$arg");

Check out the CGI docs for more information on parameters and redirects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜