[英]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.