Re: [htmltmpl] Select/option How to set "selected"?
Brought to you by:
samtregar
From: Puneet K. <pk...@ei...> - 2004-05-03 21:13:47
|
Mark Fuller wrote: > I am creating a select list where all the "option" content comes from a > mySQL table. The following works fine: > > ==================== > Occupation: <select name="occupation"> > <TMPL_LOOP NAME=OCCUPATION_LOOP> > <option value="<TMPL_VAR NAME=VAL>"><TMPL_VAR NAME=TEXT></option> > </TMPL_LOOP> > ==================== > > How can I specify a row should be "selected"? The TMPL_VAR named "VAL" is a > numeric index. If I could use TMPL_IF and concatenate the value of "VAL", I > think it would work. > > <TMPL_IF NAME="SEL"<TMPL_VAR NAME="VAL">> > selected > </TMPL_IF> > > In my program I could set "$sel5 = 1". > > Is there any way to do this? > there are several ways to do this. I prefer simply constructing my sql in such a way that the selected value is identified SELECT val, text, (if then else to return 'selected' or '') AS selected FROM table WHERE whatever... then in my template... <tmpl_loop occupations> <option value="<tmpl_var val>" <tmpl_var selected>> <tmpl_var text> </option> </tmpl_loop> |