Hi,
I have this issue where I have created a form (using Laravel), it looks like this in part:
{{-- Choose a category from the radios provided, this is where I need to get the $category->id and pass it to the next element for the sub category selection --}} <div class="form-group"> <p><b>Choose a category:</b></p> @foreach (AppHttpModelsGalleryCategories::all() as $category) {!! Form::label('category_id', $category->name) !!} {!! Form::radio('category_id', $category->id, null, ['class' => 'form-field']) !!} @endforeach </div> {{-- Using the category id passed to this form-group I can then access only the sub categories that have a gallery_categories_id = category --}} <div class="form-group"> <p><b>Choose a sub category:</b></p> @foreach (AppHttpModelsGallerySubCategories::all() as $sub_category) {!! Form::label('sub_category_id', $sub_category->name) !!} {!! Form::radio('sub_category_id', $sub_category->id, null, ['class' => 'form-field']) !!} @endforeach </div>
The way I have the database setup is that a category has many sub categories. So first it will display a list of categories, something like:
cat1 ( ) cat2 ( ) cat3 ( ) ...
Then the form will display the sub categories like this:
subcat1 ( ) subcat2 ( ) subcat3 ( )
But what I want to do is that when someone selects a category I want to capture that $category->id and then pass it immediately to the next form element that will then display the sub categories that relate to that category.
Easy enough if I was to break it all down and submit a couple of forms to pass the data back and forth however I wanted to be able to achieve this without the form being submitted.
It has been suggested that JS would be the best way to acomplish this, I am not sure. What do you think?
Thanks