0

I would like to implement something like the country section in payment where you select the field and a dropdown is generated on the select.

I know that's it works using chosen.js but I cannot find a tutorial and how to do this.

Any help would be greatly appreciated.

Thanks

4

1 回答 1

0

It's relatively simple, you will require two drop-down boxes, one with a series of countries, and the other which we will fill with currencies related to those countries (I assume this is what you are aiming for?). Something like this:

HTML:

<select id="countries">
    <option value="US">US</option>
    <option value="UK">UK</option>
    <option value="FR">France</option>
</select>

<select id="currencies">
    <option>US Dollars (USD)</option>
    <option>Some other currency!?</option>
</select>

jQuery

$(document).ready(function()
{
    $("#countries").change(function()
    {
        // Empty the current options out
        $("#currencies").empty();

        // Split by the country chosen
        switch($("#countries").val())
        {
            case "US":
            {
                $("#currencies").append("<option>US Dollars (USD)</option>");
                $("#currencies").append("<option>Some other currency!?</option>");
                break;
            }
            case "UK":
            {
                $("#currencies").append("<option>Great British Pounds (GBP)</option>");
                $("#currencies").append("<option>Euros (Sorta!)</option>");
                break;
            }
            case "FR":
            {
                $("#currencies").append("<option>Euros (EUR)</option>");
                $("#currencies").append("<option>Francs (Old...)</option>");
                break;
            }
        }
    });
});

JSFiddle http://jsfiddle.net/dmDy8/

于 2013-11-14T14:57:30.850 回答