** У меня проблема с laravel многократным добавлением с динамической зависимостью c. Во-первых, зависимость работает независимо от того, но когда я добавляю другую строку динамически (с помощью кнопки addmore), зависимость не работает. **
При этом отправляю мой html и javascript код
<script>
$(document).ready(function(){
var count = 1;
dynamic_field(count);
function dynamic_field(number)
{
html = '<tr>';
html += '<td><select name="sndynamic[]" id="sndynamic" class="form-control"><option value="0" disable="true" selected="true">==Select Section== </option> @foreach($sectiondynamicr as $key => $value)<option value="{{$value->id}}"> {{$value->section_name}}</option> @endforeach</select></td>';
html += '<td><select name="gndynamic[]" id="gndnamic" class="form-control abc" /> </select></td>';
html += '<td><select name="allndynamic[]" id="allndynamic" class="form-control cde" /></td>';
if(number > 1)
{
html += '<td><button type="button" name="remove" id="" class="btn btn-danger remove">Remove</button></td></tr>';
$('tbody').append(html);
}
else
{
html += '<td><button type="button" name="add" id="add" class="btn btn-success">Add</button></td></tr>';
$('tbody').html(html);
}
}
$(document).on('click', '#add', function(){
count++;
dynamic_field(count);
});
$(document).on('click', '.remove', function(){
count--;
$(this).closest("tr").remove();
});
});
$(document).ready(function(){
$('#sndynamic').on('change',function(e){
console.log(e);
var sectionss_id=e.target.value;
$.get('/gradedynamic?sectionss_id='+sectionss_id,function(data){
console.log(data);
$('#gndnamic').empty();
$('#gndnamic').append('<option value="0" disable="true" selected="true">==Select Grades== </option>');
$.each(data,function(index,a){
$('#gndnamic').append('<option value=" '+a.id+'">'+a.grade_name+'</option>');
});
});
});
$('#gndnamic').on('change',function(e){
var grade_id=e.target.value;
$.get('/allclassdynamic?grade_id='+grade_id,function(data){
console.log(data);
$('#allndynamic').empty();
$('#allndynamic').append('<option value="0" disable="true" selected="true">==Select All Classes== </option>');
$.each(data,function(index,allclassObj){
$('#allndynamic').append('<option value=" '+allclassObj.id+'">'+allclassObj.class_name+'</option>');
});
});
});
});
</script>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Section</title>
<title>Dash Board</title>
{!!HTML::style('bootstrap-3.3.6-dist/css/bootstrap-theme.css')!!}
{!!HTML::style('bootstrap-3.3.6-dist/css/bootstrap.css')!!}
{!!HTML::script('js/jquery.min.js')!!}
{!!HTML::script('js/bootstrap.min.js')!!}
{!!HTML::script('js/dataTables.bootstrap.min.js')!!}
{!!HTML::script('js/buttons.flash.min.js')!!}
{!!HTML::script('js/buttons.html5.min.js')!!}
</head>
<body>
<div class="container">
<br />
<h3 align="center">Section, Grade, Class</h3>
<br />
<div class="table-responsive">
<form method="post" id="dynamic_form">
<span id="result"></span>
<table class="table table-bordered table-striped" id="user_table">
<thead>
<tr>
<th width="35%">Section</th>
<th width="35%">Grade</th>
<th width="35%">Class</th>
<th width="30%">Action</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="2" align="right"> </td>
<td>
@csrf
<input type="submit" name="save" id="save" class="btn btn-primary" value="Save" />
</td>
</tr>
</tfoot>
</table>
</form>
</div>
</div>
</body>
</html>
Это мой код Html и код javascript для вашего внимания.