You can use this code for your form
{!! Form::select('numberOfChildren',range(0,10),old('numberOfChildren'),['id'=>'numberOfChildren']) !!}
And Jquery you should change
index = this.selectedIndex;
with
index = $(this).val();
Hi, the form is sent to another page, so when the submit button is pressed the values are stored correctly in the session but the children's ages are set back to default, being 1.
So I need the session values put back into the childrens ages.
I think this code is bestter for you
{!! Form::open(['url'=>'test']) !!}
{!! Form::select('numberOfChildren',range(0,10),null,['id'=>'numberOfChildren'])!!}
<div id="add_select">
@for($i=0;$i<10;$i++)
{!! Form::select('age_'.$i,range(1,14),null,['style'=>'display:none;','id'=>'age_'.$i,'class'=>'age_child'])!!}
@endfor
</div>
{!! Form::submit('Submit')!!}
{!! Form::close()!!}
<script>
$('#numberOfChildren').change(function(){
var index = $(this).val();
for(var u=0; u<index; u++){
$('#age_'+u).show();
}
}).trigger('change');
</script>
I tested. It very ok
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community