Create new select with the button using array

Asked

Viewed 18 times

0

I am trying to create a button so that there is the creation of a new select according to the need to fill and a delete button to delete those that have no need without deleting the first item. I’m trying to create an array that does the work of changing the name field according to the creation number of select but I’m not getting it. Could you help me? I would also like to know how to create a function that would add new columns in the bd according to the creation of new selects. grateful to all

            <div class="form-group col-md-5">
                <label for="name">Proprietário</label>
                <div id="prop" class="prop form-group col-md-10">
                    <select name="prop_[]" id="propSelect" oninput="this.className = ''"
                    class="
                    form-control mr-2" placeholder="Selecione o Proprietário">
                        <option value="">Selecione o Proprietário</option>
                        <?php
                        foreach($users as $user) {
                            echo "<option value='{$user->id}'>{$user->name}</option>";
                        }
                        ?>
                    </select>
                </div>
                <div id="add"></div>
                <a onclick="" style="cursor: pointer;" type="button" class="bprop btn btn-warning rounded-circle mr-2"><i class="icofont-plus"></i></a>
                <a type="button" onclick="" class="excProp btn btn-danger rounded-circle mr-2"><i class="icofont-trash"></i></a>
            </div> ```

```$(document).ready(function(){
  var select = $(".test #prop").length
  var values = []
  values.push($(".test #prop").length)
  
 
  console.log(values)
  values.forEach(function(x){
    $(".test select").attr("name","prop_"+[x])
  })
      $(".bprop").on("click", function(){
      var clone = $("#prop").clone()
      clone.appendTo("#add")
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.