Exemple : imaginez un table of babies
, avec chaque ligne, les utilisateurs sélectionnent bébé GenderDropDown , puis sélectionnez un nom. Je dois empêcher la sélection de noms en double dans la table. Si l’utilisateur sélectionne Homme et John, il ne peut pas le sélectionner à nouveau dans une autre ligne. À l’exception des bébés, Ma table
comporte des lignes contenant des projets et des codes de code en tant que DropDowns . Si vous disable
une option de sélection dans la liste déroulante, elle ne sera pas postée au serveur!
$('.timecodeDdlId').find('option[value=' + $(this).val() + ']').prop('disabled', true);
fonctionne mais désactivé ne POST pas la valeur sélectionnée au serveur
Question : Comment puis-je empêcher la sélection de doublons dans la deuxième liste déroulante ? Alors que j’ai trouvé des réponses sur So here . Cependant, ils échouent – et n’affichent pas sur le serveur **. $('.timecodeDdlId').find('option[value=' + $(this).val() + ']').prop('disabled', true);
ne POST pas au serveur.
Tableau d’extraits HTML RENDU, avec des lignes DropDown
//ROW 1 Modeling Ventosanzap Modeling Budget-070 Budget-070 Budget-784 //ROW 2 Modeling Ventosanzap Modeling Budget-070 Budget-070 // HOW TO PREVENT DUPLICATE AND STILL POST TO SERVER Budget-784 //
JAVASCRIPT OnChange pour empêcher les sélections en double
//Disable other previous/next selected TimeCodes On Change $('#TS').on('change', '.timecodeDdlId', function () { //baby name check //Is this the correct dropdown we are selecting why not $this? var allSelectedBillingCodeDropDown = $('#TS .timecodeDdlId option:selected'); var thisBillingSelectedDropDown = $(this); var currentSelectBillingCode = $(this).val(); // get exisiting vlaue seelections $.each(allSelectedBillingCodeDropDown, function (index, item) { if ($(item).val() == currentSelectBillingCode) { debugger; // remove this selection //selectedBillingCodeDropDown.find('option[value=' + currentSelectBillingCode + ']').remove(); thisBillingSelectedDropDown.find('option[value=' + currentSelectBillingCode + ']').remove(); //alert userd alert('Billing code cannot be the same'); return false; } // $('#select_id').find('option[value=' + foo + ']').remove(); //item.remove all });
You can try this way $(document).ready(function() { $("select").on('hover', function () { $previousValue = $(this).val(); }).change(function() { $("select").not(this).find("option[value='"+ $(this).val() + "']").attr('disabled', true); $("select").not(this).find("option[value='"+ $previousValue + "']").attr('disabled', false); }); }); $("#confirm-form").submit(function(e) { e.preventDefault(); $("select").find("option").removeAttr('disabled'); document.getElementById('confirm-form').submit(); });