Tags:
create new tag
view all tags

Question

I want to have a drop down menu of items which show the selected values after the form has been submitted. Like the one shown below:

<select name="test1">
<option %IF{"'%URLPARAM{"test1"}%'='A'" then="selected='selected'"}%>A</option>
<option %IF{"'%URLPARAM{"test1"}%'='B'" then="selected='selected'"}%>B</option>
<option %IF{"'%URLPARAM{"test1"}%'='C'" then="selected='selected'"}%>C</option>
</select>

This works for all values

I want the drop down items to be picked from the table, like the one given below:

Parameter Value
test A
test B
test C

<select name="test2">
%SEARCH{ "^\| *test *\|" topic="PersistentSelectedValues" type="regex" multiple="on" nosearch="on" nototal="on" format="<option %IF{"'%URLPARAM{"test2"}%'='C'" then="selected='selected'"}%>$pattern(^\| *test *\| *(.*?) *\|.*)</option>" separator=" "}%
</select>

Works if C is chosen

I want it to work for any value but it does not work !

<select name="test3">
%SEARCH{ "^\| *test *\|" topic="PersistentSelectedValues" type="regex" multiple="on" nosearch="on" nototal="on" format="<option %IF{"'%URLPARAM{"test3"}%'='$pattern(^\| *test *\| *(.*?) *\|.*)'" then="selected='selected'"}%>$pattern(^\| *test *\| *(.*?) *\|.*)</option>" separator=" "}%
</select>

Does not work for any value ! (Goes back to 'A' )

What am I missing ?

Environment

TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Windows 2003
Web server: Apache 1.3.39
Perl version: 5.008008 (cygwin)
Client OS: Windows XP
Web Browser: IE 6
Categories: Forms

-- ChengappaCB - 20 Dec 2008

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

I usually simply add this in the beginning:

<option>%URLPARAM{status}%</option> <option></option>
, followed by the actual options. The first option is selected by default, e.g. it "remembers" the submitted option because of the URL parameter. The second option is empty to unselect an option, which is useful in a query-by-example form. One disadvantage of this approach is that the selected value is listed twice (in the beginning and in the actual list).

Your approach is more intuitive because it lists options only once. Make sure to escape the IF and URLPARAM with $percnt so that it survives the SEARCH. Escape also double quotes where needed.

Untested format example:

format="<option $percntIF{\"'$percntURLPARAM{test3}$percnt'='$pattern(^\| *test *\| *(.*?) *\|.*)'\" then=\"selected='selected'\"}$percnt>$pattern(^\| *test *\| *(.*?) *\|.*)</option>"

-- PeterThoeny - 21 Dec 2008

Thanks a lot Peter. You have been helpful as ever. It looks like the % in URLPARAM need not (or should not ?) be escaped. Here is what worked.

<select name="test4">
%SEARCH{ "^\| *test *\|" topic="PersistentSelectedValues" type="regex" multiple="on" nosearch="on" nototal="on" format="<option $percntIF{\"'%URLPARAM{"test4"}%'='$pattern(^\| *test *\| *(.*?) *\|.*)'\" then=\"selected='selected'\"}$percnt>$pattern(^\| *test *\| *(.*?) *\|.*)</option>" separator=" "}%
</select>

Just a last question: Is it possible to use the 'value=' parameter in <option> so that I can assign some numerical values to the URLPARAM, based on the dropdown option selected ? In the above mentioned example, I want the URLPARAM{test4} to be assigned values 1,2 or 3 (or any other values like 10,100 or 1000) respectively if A , B or C are selected.

-- ChengappaCB - 21 Dec 2008

Standard HTML:

<option value='100'>A</option>

-- PeterThoeny - 21 Dec 2008

I was actually looking for some way to use this within SEARCH command above. May be I can figure out some way of doing it. Anyway, thanks a lot for all the help.

-- ChengappaCB - 22 Dec 2008

Well... just for the sake of completeness... I solved this by introducing the third column to the table with the values corresponding to the entries in the second column. With a bit of tweaking the $pattern variable, I am able to pick the correct value now.

-- ChengappaCB - 22 Dec 2008

Nice. May be you could summarize it for others as a reference?

-- PeterThoeny - 22 Dec 2008

This is also worth a blog article in the Blog web.

-- PeterThoeny - 22 Dec 2008

I will Peter. I owe one to Twiki smile

-- ChengappaCB - 26 Dec 2008

Change status to:
Edit | Attach | Watch | Print version | History: r8 < r7 < r6 < r5 < r4 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r8 - 2008-12-26 - ChengappaCB
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.