Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging smarty variable's value with AJAX; multiple selects
    text
    copied!<p>I have 3 selects on a page, the 2nd and 3rd select should populate with options depending on the value selected in the first select. For instance: the first select has a list of countries, if I select country <strong>A</strong> from this select, the 2nd select will populate with cities from this country, the 3rd select populates with, i don't know, most popular names in the country.</p> <p>I want to realize this with AJAX, but because the site is written with the use of Smarty, I'm having a hard time. Each select is populated by an array which is assigned from a php. I would like to somehow change the values of the 2nd and 3rd array, without reloading the page, depending on an id I get from the 1st select. </p> <p>I tried requesting the page that assigns the values to smarty and tried changing the arrays but it didn't work in the frontend. Any ideas?</p> <p><strong>EDIT:</strong> The code looks something like this:</p> <pre><code>$countries = Country::getCountries(); $cities = City::getCities($country_id); //the parameter is not necessary $names = Name::getNames($country_id); //the parameter is not necessary $smarty-&gt;assign("countries",$countrires); $smarty-&gt;assign("cities",$cities); $smarty-&gt;assign("names",$names); //display template etc </code></pre> <p>on the template page</p> <pre><code>&lt;select name="countries"&gt; {foreach from=$countries item=country} &lt;option value="{$country.id}"&gt;{$country.name}&lt;/option&gt; {/foreach} &lt;/select&gt; </code></pre> <p>and the 2 other selects look the same. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload