Re: [htmltmpl] Select/option How to set "selected"?
Brought to you by:
samtregar
From: Mathew R. <mat...@re...> - 2004-05-03 22:55:15
|
The difference would be not be measurable unless you did a 1,000,000 = instantations, then timed the results, since both Perl and H::T are = reasonably quick a text processing. Mathew ----- Original Message -----=20 From: "Mark Fuller" <mar...@ea...> To: <ja...@jo...> Cc: <htm...@li...> Sent: Tuesday, May 04, 2004 8:43 AM Subject: Re: [htmltmpl] Select/option How to set "selected"? > Jason, thanks. The way you do the push helped me. I was putting the = values > into a temporary hash and then assigning the hash as a reference. I = wanted > to do it more directly like you did, but didn't know the semantics. >=20 > Regarding this: >=20 > > $selected =3D 1 if i_want_this_option_selected( $option ); > and > > <TMPL_LOOP NAME=3DOCCUPATION_LOOP> > > <option value=3D"<TMPL_VAR NAME=3DVAL>" <TMPL_IF > > NAME=3D"SELECTED">SELECTED</TMPL_IF>><TMPL_VAR NAME=3DTEXT></option> > > </TMPL_LOOP> >=20 > Do you think this is more efficient, or is it more efficient to do as = Puneet > suggested: >=20 > > $selected =3D ' selected' if i_want_this_option_selected( $option = ); > and > > <TMPL_LOOP NAME=3DOCCUPATION_LOOP> > > <option value=3D"<TMPL_VAR NAME=3DVAL>"<TMPL_VAR = NAME=3DSELECTED>><TMPL_VAR > NAME=3DTEXT></option> > > </TMPL_LOOP> >=20 > It seems to me the latter would be more efficient? If I am already = testing > my criteria for selected, then I don't have to do an "if" again in the = HTML. > In other words, is it more efficient to resolve the variable contents, = or to > test variable? >=20 > Mark >=20 > ----- Original Message -----=20 > From: "Jason Purdy" <ja...@jo...> > To: "Mark Fuller" <mar...@ea...> > Cc: <htm...@li...> > Sent: Monday, May 03, 2004 2:36 PM > Subject: Re: [htmltmpl] Select/option How to set "selected"? >=20 >=20 > > Hi Mark, > > > > How are you determining which option to pre-select? It might be = better > > to use HTML::FillInForm. > > > > Other than that, here's what you would do if you want to re-invent = the > > wheel: > > > > ### In your programming code ### > > my $template =3D HTML::Template->new( 'filename' =3D> 'file.TMPL' ); > > my $occloop_ar =3D []; # occupation loop array ref. > > while ( my ( $option, $value ) =3D $sth->fetchrow_array ) { > > my $selected =3D 0; > > $selected =3D 1 if i_want_this_option_selected( $option ); > > push @$array_ref, { > > 'VAL' =3D> $option, > > 'TEXT' =3D> $value, > > 'SELECTED' =3D> $selected, > > }; > > } > > $template->param( 'OCCUPATION_LOOP' =3D> $occloop_ar ); > > > > ### Then in your template code ### > > Occupation: <select name=3D"occupation"> > > <TMPL_LOOP NAME=3DOCCUPATION_LOOP> > > <option value=3D"<TMPL_VAR NAME=3DVAL>" <TMPL_IF > > NAME=3D"SELECTED">SELECTED</TMPL_IF>><TMPL_VAR NAME=3DTEXT></option> > > </TMPL_LOOP> > > > > Cheers, > > > > Jason > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by: Oracle 10g > > Get certified on the hottest thing ever to hit the market... Oracle = 10g. > > Take an Oracle 10g class now, and we'll give you the exam FREE. > > http://ads.osdn.com/?ad_id=3D3149&alloc_id=3D8166&op=3Dclick > > _______________________________________________ > > Html-template-users mailing list > > Htm...@li... > > https://lists.sourceforge.net/lists/listinfo/html-template-users >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: Oracle 10g > Get certified on the hottest thing ever to hit the market... Oracle = 10g.=20 > Take an Oracle 10g class now, and we'll give you the exam FREE.=20 > http://ads.osdn.com/?ad_id=3D3149&alloc_id=3D8166&op=3Dclick > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |