我猜,你的描述是:當你點擊提交按鈕,那麼你的CGI腳本將運行,給出你在表格中輸入的參數,然後我必須做的是:寫回一些東西並重新打印表格 - 使用不同的值
所以,即使這不是完成這樣的事情的完美方式對於簡單的表單元素替換,你應該做它的客戶端和使用JavaScript - 你不需要一個CGI後端腳本),讓我們看看一個CGI腳本可能看起來像。
首先,知道如何編寫表單很重要。讓我們假設你用印刷品「寫得很難」。 腳本必須做的是解析輸入,然後將其作爲值添加到輸出。
use CGI;
my $q = CGI->new;
# get the value from the popup/html select
my $popup_value = $q->param('popup_menu'); # name of the <select name="..."> in your html
# ...
# writing the form
print $q->header;
# some more prints with form etc.
print textarea(-name => 'text_area',
-default => $popup_value // '', # will use empty string on first call
);
# Don't turn off autoescaping !
BTW,選擇期權的價值,就是要短的指標,而不是全文(即使這可能是能夠達到一定數目的字符)。因此,您可能會想到在文本區域中打印一個散列或具有適當值的陣列,併爲您的選項選擇值0,1,2 ...
my @text_values = ('', 'First text', 'second text', 'third text');
my $popup_value = $q->param('popup_menu') || 0; # default index.
# now use 1,2,3, ... as values in your popup_menu options
# ...
print textarea(-name => 'text_area',
-default => $text_values[$popup_value]);
這沒有任何意義。表單提交後,如何「從popup_menu中選擇另一個元素」?那時沒有菜單甚至HTML頁面。 – ikegami
Perl是服務器端。 Javascript是客戶端。 – shaun5
我不是按照你的工作流程,但刪除一個CGI對象的內容可以不是這樣的: $ cgi-> param(-name =>'foo',-value =>''); –