如何从< option>中检索循环值属性标记,并传递给< select>中的onchange属性.标签 [英] How to retrieve looped value attributes from <option> tag and pass to the onchange attribute in <select> tag

查看:80
本文介绍了如何从< option>中检索循环值属性标记,并传递给< select>中的onchange属性.标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用laravel框架,我创建了一个下拉框,并通过循环从数据库中填充项目.

I'm using the laravel framework and I created a drop down box and populated it with items from the database by looping.

<select class="form-control" id="username" name="username" onchange="handleSelect(elm)">     
                <option value="" selected>Select User</option>
                @foreach($getUsers as $list)
                <option value="{{$list->id}}" >{{$list->name}}</option>
                @endforeach

            </select>

我希望在单击下拉列表中的项目时,将所单击的项目的值传递到url中.基本上,我想重新加载页面,并单击要对页面进行更改的项目.我想到的一种方法是将单击的选项的值传递给handleSelect()函数,但我不知道该怎么做.

I want when I click an item in the drop down list, the value of the item clicked is passed in a url. Basically I want to reload the page with the item clicked to make changes to the page. A way I thought of doing it was to pass the value of the option clicked to the handleSelect() function but I don't know how to do that.

handleSelect()不执行任何操作.我只是想将选定的循环值属性中的内容传递给handleSelect()函数.

edit: the handleSelect() doesn't do anything. I'm just trying to pass what is in the selected looped value attribute to the handleSelect() function.

推荐答案

一个非常基本的javascript函数,用于处理每当用户从菜单中选择一个选项时触发的onchange事件

A very basic javascript function to handle the onchange event that is fired whenever the user selects an option from the menu

function handleSelect(e){
    /* find element name and assign the value */
    location.search=[ e.target.name, e.target.value ].join('=');
}

这篇关于如何从&lt; option&gt;中检索循环值属性标记,并传递给&lt; select&gt;中的onchange属性.标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆