简体   繁体   English

使用JavaScript获取表单的上一个值以创建下一个

[英]Using JavaScript to get the previous value of a form in order to create the next

Probably best if I show you what I have first. 如果我告诉你我先拥有的东西,可能最好。 I am using PHP/MySQL and Laravel 5. 我正在使用PHP / MySQL和Laravel 5。

<div class="form-group">
    <p><b>Assign a category:</b></p>
    @foreach (App\Http\Models\GalleryCategories::all() as $category)            
        {!! Form::label('category_id', $category->name) !!}
        {!! Form::checkbox('category_id', $category->id, null, ['class' => 'field']) !!}                
    @endforeach
</div>

That part gets some categories from the database, loops through and creates a series of radio boxes so that the uploader can select one. 该部分从数据库中获取一些类别,循环浏览并创建一系列单选框,以便上传者可以选择一个。 Only one. 只有一个。

However what I need is some code, I am told JavaScript is best to get the ID of the category the uploader has selected in order to then do another loop for sub category list connected to the category. 但是我需要一些代码,我被告知JavaScript最好是获取上载者选择的类别的ID,然后对连接到该类别的子类别列表进行另一个循环。

Of course the issue is that I need to pass the category ID the user has chosen before the form is submitted. 当然,问题在于,在提交表单之前,我需要传递用户选择的类别ID。 In effect I need to have the $category_id available as soon as the person selects one in order to then generate the next set of radio boxes. 实际上,只要此人选择一个,我就需要有$ category_id,以便生成下一组收音机框。

Anyone ideas how to do that? 任何人都想怎么做?

我知道了,它使用一些JavaScript来设置将ID传递给表单下一部分的onclick事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM