Home > Mobile >  how to add and remove tr along with dropdown list in laravel?
how to add and remove tr along with dropdown list in laravel?

Time:03-15

i have a table form which has Drop down list which has @foreach loop and i want to add more rows and with same values here is the code

 <tbody>
    <tr>
      <td> 
        <select  name="room">
                    <option value="" disabled>Select Room</option>
                    @foreach($rooms as room)
                    <option value="{{room->id}}">{{$room->type}}</option>
                        </select>
                    <span ></span>
                    
             </td>
             
             <td>
                 <input type="number"   name="roomnumber" />
                  </td>
             <td>
                <a href="" > </a>
                <a href="" >-</a>
             </td>

    </tr>

  </tbody> 

and here is the javascript

<script src="{{asset('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js')}}"></script>
<script>
  $(".addmore").on('click',function(){
        var data ="<tr><td>FirstTD</td> <td>SecondTD</td><td>3rdTD</td><td>4thTD</td></tr>";
        $('#myTable').find('tbody').append(data);
});
</script>

there are two problems first the tr append and disappear after a second , second i dont know how to add the @foreach in jquery , is jquery accept compact variable in blade

CodePudding user response:

First question tr append and disappear after a second :

<a href="" > </a>

this href let your web reload delete href

Sec: do you want to copy the same row which you click ? try this

data ='<tr>'  $(this).closest('tr').html()  "</tr>";
  • Related