0

I want to ask 2 questions.

  1. I have created dynamic dropdown (class and section) using jquery and assign the id's like [myclass0, myclass1] [mysection0, mysection1] etc. Now I want to retrieve the values of both and store in a variable or array then I will use these variable for sending it to database. I have done the following code but it's not working and even it's not showing the ID of dynamic created dropdown.
  2. How to select the values of classes and sections and how to loop them so that valid data will be sent to database?

here is my code

   <div class="row">
    <div class="col-sm-12" id="dynamic_select">     
    </div>
</div>
<input type="button" name="" value="Add Class" class="btn btn-primary" id="addclass" style="margin-top: 50px;" onclick="addMore();">

here is my JS:

function addMore(){
          var inps = $('#dynamic_select > div:last').data('count')+1 || 0;
          $('#dynamic_select').append('<div data-count="'+inps+'"><div class = "col-sm-5"><label>Select Class</label> <select id="childclass'+inps+' "  class="form-control"> <option value="9">IX</option><option value="10">X</option><option value="11">FSC I</option><option value="12">FSC II</option></select> </div>    <div class = "col-sm-5"><label>Select Section</label> <select id="childsection'+inps+' "  class="form-control"> <option value="A">A</option><option value="B">B</option><option value="C">C</option></select></div> <a class=remove>X</a>');
        }

1 Answer 1

1

Try this (example for #dynamic_select):

$('#dynamic_select select').val();

or

$('#dynamic_select).on('change', function() {
   $('#dynamic_select select').val();
});
Sign up to request clarification or add additional context in comments.

1 Comment

It is working only if you add one class but Let's say I have created 3 dynamic dropdown, Now how can I store classes and sections on different variables.

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.