简体   繁体   English

如何从中检索循环值属性 <option>标记并传递到中的onchange属性<select>标签

[英]How to retrieve looped value attributes from <option> tag and pass to the onchange attribute in <select> tag

I'm using the laravel framework and I created a drop down box and populated it with items from the database by looping. 我正在使用laravel框架,并创建了一个下拉框,并通过循环用数据库中的项目填充了它。

<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>

I want when I click an item in the drop down list, the value of the item clicked is passed in a url. 我想当我单击下拉列表中的项目时,所单击的项目的值在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()函数,但是我不知道该怎么做。

edit: the handleSelect() doesn't do anything. 编辑:handleSelect()不执行任何操作。 I'm just trying to pass what is in the selected looped value attribute to the handleSelect() function. 我只是想将选定的循环值属性中的内容传递给handleSelect()函数。

A very basic javascript function to handle the onchange event that is fired whenever the user selects an option from the menu 一个非常基本的javascript函数,用于处理每当用户从菜单中选择一个选项时都会触发的onchange事件

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

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

相关问题 如何使用jQuery数据表的onChange事件从html select标签选项值中获取值? - How to get value from html select tag option value using onChange event using jQuery data table? 从选项html标记中检索值并传递给另一个servlet - Retrieve value from option html tag and pass to another servlet 如何从React中选项标签上的自定义属性中检索数据 - How to retrieve data from custom attribute on option tag in React 选择选项onchange时在锚标记中显示值 - Show value in anchor tag when select option onchange 无法检索选项标签属性 - Unable to retrieve option tag attribute 如何从选项标签值属性替换值 - How can i replace value from the option tag value attribute 如何将 select 标签中的选项传递给另一个 select 标签? - How can I pass an option in a select tag to another select tag? 使用Dalekjs测试工具,当Option标记中没有“值”属性时,如何在Dropdown(选择元素)中选择Option? - Using Dalekjs test tool, how to select Option in Dropdown(Select element) when there is no “value” attribute in Option tag? 如何通过onChange事件将对象值传递给select标签? - how to pass the the object values to the select tag with onChange event? 如何将两个 arguments 传递给 select 标签中的 onchange 处理程序? - How to pass two arguments to an onchange handler in a select tag?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM