Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How is selected=<variable> in html_options resolved?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
rgbiggs
Smarty n00b


Joined: 24 Jul 2003
Posts: 1
Location: Seattle, WA

PostPosted: Thu Jul 24, 2003 12:32 am    Post subject: How is selected=<variable> in html_options resolved? Reply with quote

I am trying to write a script that allows me to show only the states for the country selected in another dropdown list.

Given: {html_options values=$states_values output=$states_output selected=$formdata.state}

Given: my database lists all 50 states + Canadian provinces + Mexican states (so it one long list).

Given: I filter for just provinces (so the state dropdown list has only Canadian provinces in it), and

Given: On reload of the page, selected=$formdata.state will select the state in the values-posted array. Does Smary select the state by index or by value? If I select Saskatchewan, that would be an index of 62, but without all the US states, it would be an actual index of 12.

The ultimate question is, can I have a country selector with Smarty where I can dynamically populate and repopulate a state dropdown (with JavaScript) and have the state remembered and re-selected with selected=$formdata.state when returning to the page?
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Jul 24, 2003 3:11 am    Post subject: Re: How is selected=<variable> in html_options resolve Reply with quote

rgbiggs wrote:
The ultimate question is, can I have a country selector with Smarty where I can dynamically populate and repopulate a state dropdown (with JavaScript) and have the state remembered and re-selected with selected=$formdata.state when returning to the page?


Sure! The way I see it, Smarty doesn't really come into play unless you write your own custom plugin to encapsulate all of the js code and conditions that you have. Otherwise, what you need to do is have your page know which array is currently selected, which I think you already have in another dropdown for country (?). In otherwords, I don't see how this is any different from a normal select in terms of the form handling. You should be able to Do What You Expect(tm).

I noticed that you cross-posted this in two forums--that is unnecessary and I have removed the other one in case you are looking for it. One post is not only sufficient, it also keeps all replies together for future reference.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP