Apologies, this should have posted to jQuery.


On Aug 21, 3:55 pm, Todd Chambery <[email protected]> wrote:
> Hi all,
>
> I'm having a devil of a time removing options from a select.  Here's
> the scenario:
>
> I have one <select> that when an item is chosen, that item will be
> removed from all the other <select>s containing the same data:
>
> <select onchange="update_feat_sub_selection(chardata, 75, 0)"
> id="feat_75_multi_0">
>         <option value="0" id="feat_75_multi_0_option_0">Axe, Orc double</
> option>
>         <option value="1" id="feat_75_multi_0_option_1" selected='true'>Axe,
> throwing</option>
>         <option value="2" id="feat_75_multi_0_option_2">Battleaxe</option>
>         ...
> </select>
> <select onchange="update_feat_sub_selection(chardata, 75, 1)"
> id="feat_75_multi_1">
>         <option value="0" id="feat_75_multi_1_option_0">Axe, Orc double</
> option>
>         <option value="1" id="feat_75_multi_1_option_1">Axe, throwing</
> option>
>         <option value="2" id="feat_75_multi_1_option_2">Battleaxe</option>
>         ...
> </select>
>
> So in this case I want "Axe, throwing" removed from the second
> select.  Because there can be multiple select instances, I have to
> iter over each of them and remove all the selected items any time any
> one of them changes.  My (non-working) idea was to:
>
>   1) create a new select containing all items,
>   2) replace the current select, and
>   3) use the texotela (http://www.texotela.co.uk/code/jquery/select/)
> plugin to remove the options that match values stored in an array:
>
> function update_feat_sub_selection(chardata, feat_id, multi_idx) {
>         var weapon_id = $('select#feat_' + feat_id + '_multi_' +
> multi_idx).val();
>         var row = chardata.feats.first( {
>                 feat_id : feat_id
>         });
>
>         row.weapons[multi_idx] = weapon_id;
>         chardata.feats.update(row, {
>                 feat_id : feat_id
>         });
>
>         sav(chardata);
>
>         // remove the changed weapon from the lists of all other weapons
>         $("select[id^='feat_" + feat_id + "_multi_']").each(function(x,
> select) {
>                 // skip this one (obviously
>                 if ($(this).attr('id') != 'feat_' + feat_id + '_multi_' + 
> multi_idx)
> {
>                          feat = feats.first({
>                                  id: feat_id
>                          });
>                          rebuilt_select = 
> create_multi_feat_weapon_selector(feat, x);
>                          // replace the old select with the new one with the 
> full suite of
> weapons
>                          $('tr#feat_' + feat_id + '_multi_' + x).replaceWith
> (rebuilt_select);
>                          $(this).attr('value', selected_weapon_id);
>                         // remove already selected weapons from the new 
> listing
>                          char_feat = chardata.feats.first({
>                                  feat_id: feat_id
>                          });
>                          $('select#feat_' + feat_id + '_multi_' + 
> x).removeOption
> (char_feat.weapons);
>                 }
>         });
>
> }
>
> My <tr> is getting replaced correctly, but no options are removed.
>
> I've been round the horn on this one, I'll take any suggestions.
>
> Thanks,
>
> Todd
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to