开发者

jquery select list and $_POST help

I have a select list, currently I have it implemented then when the user selects an item, the I have some javscript that creates a li on the fly on the places on the page, the problem is that I want the user the be able to select multiple items from the list, however the javascript cannot cope with this, but I need this functionality so that when I submit the form the values of the selct list go into the post.

Currently my javascript looks like this,

$('#sector').change(function() { var selected = $(this).val(); 开发者_Python百科 //alert(selected); $('#selected_sectors').prepend('<li>'+selected+'</li>'); });

Is it is possible to get this each time the user ctrl+selects and item is creates the li but and keeps the values accesible in the post?


Possibly something like this is what you're looking for (note the :selected selector).

<select id="items" multiple size="5">
    <option value="apple">Apple</option>
    <option value="orange">Orange</option>
    <option value="banana">Banana</option>
    <option value="grape">Grape</option>
</select>
<ul id="sel-items"></ul>

$('#items').change(function(e){
    $('#sel-items').empty();
    $(this).find(':selected').each(function(i,e){
        $('#sel-items').append($('<li>').text($(e).val()));
    });
});

Working Example

(Working on one now that checks for deltas between the <select> and the <ul>)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜