1

I'm trying to rewrite an example of i18n found on the network to another component. With the exact link to the combo.

An example found in the network looks

Example is:

<span style="float: right">
    <a href="?lang=en">en</a>
    |
    <a href="?lang=de">de</a>
</span

My code

<from action="" method="get">
<select name="lang" id="lang" onchange="this.form.submit();">
<option value="de">DE</option>
<option value ="en">EN</option>
</select>
</form>

I came across a problem. When I change the language i18n starts correctly, but I do not know how to check the combo of the value of the parameter - lang. The upshot is that if you change the value in the combo and submicie form is presented in the initial value. Does anyone know how to solve this problem?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
tomasz-mer
  • 3,753
  • 10
  • 50
  • 69
  • Please note that the usage of your word "combo" is confusing. A combobox is an **editable** dropdown (i.e. textbox and dropdown in one, usually achieved using CSS/JS), but you're just using a plain vanilla dropdown here. – BalusC Mar 20 '11 at 14:10

1 Answers1

1

Add the selected attribute to the HTML <option> element when the value matches. Here's a basic kickoff example which does that based on the request parameter.

<option value="de" ${param.lang == 'de' ? 'selected' : ''}>DE</option>
<option value="en" ${param.lang == 'en' ? 'selected' : ''}>EN</option>

In real it might be stored somewhere else, but it at least boils down to that you should add the selected attribute to the HTML <option> element when the value matches. You could also store it in the session yourself, see also this answer for another example.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555