我有一个像这样的组合框:
<select>
<option value="product">Product</option>
<option value="company">Supplier</option>
</select>
我希望从组合框到我的搜索表单获得价值
<span class="search_input_box">
<input type="text" name="q" id="SearchKeyword" value="What are you looking for..." onblur="if (this.value=='') this.value='What are you looking for...';" onfocus="if (this.value='What are you looking for...') this.value='';" />
</span>
我尝试在组合框中使用onchange="document.getElementById('hdModule').value=this.value"
,但它没有用。
答案 0 :(得分:1)
在<select>
代码
onchange="document.getElementById('hdModule').value=this.value"
您正在更改hdModule
的值而不是文本框(SearchKeyword
)。您需要更改文本框的值。将您的代码更改为
<select onchange="document.getElementById('SearchKeyword').value=this.value">
<option value="product">Product</option>
<option value="company">Supplier</option>
</select>
<span class="search_input_box">
<input type="text" name="q" id="SearchKeyword" value="What are you looking for..." onblur="if (this.value=='') this.value='What are you looking for...';" onfocus="if (this.value='What are you looking for...') this.value='';" />
</span>
演示:http://jsfiddle.net/kogmyLda/
修改强>
如果您不想在首次加载时选择Product
或Supplier
,请添加一个空选项,如下所示
<select onchange="document.getElementById('SearchKeyword').value=this.value">
<option></option>
<option value="product">Product</option>
<option value="company">Supplier</option>
</select>
<span class="search_input_box">
<input type="text" name="q" id="SearchKeyword" value="What are you looking for..." onblur="if (this.value=='') this.value='What are you looking for...';" onfocus="if (this.value='What are you looking for...') this.value='';" />
</span>