dynamic select in speedscript-html

cherrydan

New Member
hello!!!
i want to do a dynamic select in a form html in speedscript.
I don't know how to do.
I want to take the value blue and green from a table. How can i do?

/******************/
<form name="form1" method="post" >
<center>
<table>
<tr>
<td> Test: </td>
<td> <SELECT NAME=test>
<OPTION>
<OPTION> blue
<OPTION> green </SELECT>
</td>
</tr>
</table>
</form>
/*************************************************/
thanks
 
use this code:

Code:
<select name="cboTest">
     <option value=""></option>
     <option value="R">[COLOR="Red"]RED[/COLOR]</option>
     <option value="G">[COLOR="Green"]GREEN[/COLOR]</option>
     <option value="B">[COLOR="Blue"]BLUE[/COLOR]</option>
</select>

you if you get cboTest's value, u'll get a blank character (first option), R (for Red), G (for Green) and B for blue. The string 'RED', 'GREEN' and 'BLUE' will be seen by ur users, but u'll get 'R', 'G', and 'B' as it's value.
Note: E.g. for 'RED', instead of 'R' character for RED's value, you can use 'RED', 'COLOR1' or any strings u'd like to use.
You can put a loop between it's options too. E.g. u have a table of colors named colormstr with two fields: code and name.

Code:
<select name="cboTest">
    <option value=""></option>
    [COLOR="Blue"]<% [B]FOR EACH[/B] colormstr [B]NO-LOCK[/B]: %>[/COLOR]
       <option value="`[COLOR="Blue"]colormstr.color_code[/COLOR]`">`[COLOR="Blue"]colormstr.color_name[/COLOR]`</option>
    [COLOR="Blue"]<% [B]END[/B]. %>[/COLOR]
</select>

and if you want a (or some) color to be preselected, you can use code like this:

Code:
[COLOR="Blue"]<% 
   [B]DEF VAR[/B] vColor_Code [B]LIKE[/B] colormstr.color_code [B]INIT[/B] ''.
   [B]SET[/B] vColor_Code = 'R'. 
%>[/COLOR]
<select name="cboTest">
    <option value=""></option>
[COLOR="Blue"]    <% 
       [B]FOR EACH[/B] colormstr [B]NO-LOCK[/B]: 
          [B]IF[/B] vColor_Code = colormstr.color_code [B]THEN[/B]  
    %>[/COLOR]
       <option value="`[COLOR="Blue"]colormstr.color_code[/COLOR]`" [COLOR="Red"][B]selected="selected"[/B][/COLOR]>`[COLOR="Blue"]colormstr.color_name[/COLOR]`</option>
    [COLOR="Blue"]<% [B]ELSE[/B] %>[/COLOR]
       <option value="`[COLOR="Blue"]colormstr.color_code[/COLOR]`">`[COLOR="Blue"]colormstr.color_name[/COLOR]`</option>
[COLOR="Blue"]    <% 
       [B]END[/B]. /* END FOR EACH */
    %>
[/COLOR]</select>

You can either use {&Out} statement instead of in and out embeded speedscript. :awink:

Hope it help. :)

Regards
YoChan
 
Totally OT but:
Nice to see more people using the <% and %> tags too. Much better then the <!--WSS --> tags IMO.
I use for values always <%= and %>.

Casper
 
Back
Top