简体   繁体   English

通过onchange事件将SELECT的值传递给Javascript函数吗?

[英]Pass the value of a SELECT to a Javascript function via the onchange event?

I have a HTML page that contains a search box containing a number of textboxes. 我有一个HTML页面,其中包含一个包含许多文本框的搜索框。

The first part of the search box is a SELECT dropdown list that contains a variety of report types. 搜索框的第一部分是SELECT下拉列表,其中包含各种报告类型。 Each report type requires 1 or more of textboxes to be filled in to filter the query results. 每种报告类型都需要填写1个或多个文本框以过滤查询结果。 My goal is hide the textboxes that are not required by the current report type. 我的目标是隐藏当前报告类型不需要的文本框。

How do I pass the currently selected value from the SELECT to the Javascript function via the onchange event? 如何通过onchange事件将当前选定的SELECT传递给Javascript函数?

<select name="report_type" onchange="hide();">
<option value="full_history">Full History</option>
<option value="partial_history">Partial History</option>            
</select>
<select name="report_type" onchange="hide(this.value);">
<option value="full_history">Full History</option>
<option value="partial_history">Partial History</option>            
</select>

When doing this the function have whatever value the select currently has. 执行此操作时,函数将具有选择当前具有的任何值。

function f1()
{
var obj1= document.getElementById("img");
var obj2= document.getElementById("s1");
obj1.src=obj2.value;
}

Select Image:
    <select id="s1" onchange="f1()">
        <option value="img1.jpg">img1.jpg</option>
        <option value="img2.jpg">img2.jpg</option>
        <option value="img3.jpg">img3.jpg</option>
        <option value="img4.jpg">img4.jpg</option>

    </select> <br><br>
    <img id='img' src="img1.jpg" height="500" width="500">

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

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