w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Problèm with incrémentation on Jquery

Try something like this:

Javascript

$('.situation').on('change', function(){
    var inputSituation = $( "input.situation" );
    var s = 0;

$( "input.situation" ).each(function() {

            if ($('select.toto option:selected').text() == 'Married'){

                $(this).attr('name', 'situation[2][' + s + ']');
                $(this).attr('name', 'statut[2][' + s + ']');
                s += 1; 
            }else if($('select.toto option:selected').text() ==
'Divorced'){

               $(this).attr('name', 'situation[1][' + s + ']');
               $(this).attr('name', 'statut[1][' + s + ']');
               s += 1; 
            }/*...*/

        });

});

Because if I have understand you dont want to increment s at every loop but only when one of the condition is true.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.