开发者

How do I check the combo value and set value?

开发者 https://www.devze.com 2023-02-18 18:38 出处:网络
I\'m trying to rewrite an example of i18n found on the network to another component. With the exact link to the combo.

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&g开发者_运维问答t;
</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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消