0

I'm using ajax function to send select values to my php script, it is working fine but i have issue when there user add multiple data, i have option to add multiple add child in the form, user can add as many fields. I need a each loop here. This is my code.

 <select class="firstpiller" name="firstpiller">
        <option value="0">0</option>
        <option value="1">1</option>
     </select>

     <select class="thirdpiller" name="thirdpiller">
        <option value="2">2</option>
        <option value="3">3</option>
     </select>

       if (document.querySelector('[name=firstpiller]') != null){
        var firstpiller = document.querySelector('[name=firstpiller]').value;
        } else {
           var firstpiller = null; 
        }


        if (document.querySelector('[name=thirdpiller]') != null){
        var thirdpiller = document.querySelector('[name=thirdpiller]').value;
        } else {
           var thirdpiller = null; 
        }


        var stepVar = firstpiller + "--" + thirdpiller;

Can anyone help how should i write each loop here?

Thanks in advance.

1

1 Answer 1

2

add a common class to the select say you are given a class .myselect, now you can do something like below

var stepvar = '';
$('.myselect').each(function(value){
    stepvar += '--' + value.val(); 
});
alert(stepvar);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.