why the javascript code can't work?
the html code:
<div class="fr_search">
<select class="search_l" onchange="selectSearch(select)">
<option value="0">whole site search</option>
<option value="1">google search</option>
</select>
<form action="/" accept-charset="UTF-8" method="post" id="search-theme-form">
<input name="search_theme_form" id="edit-search-theme-form-1" size="15" value="" class="form-text" />
。。。。。。
</form>
</div>
the js code:
function selectSearch(select) {
var form = select.form;
var selectedIndex = select.selectedIndex;
if (selectedIndex === 1) {
alert('test');开发者_如何学运维
form.method="get";
}
}
when i select the google from the down list, why it can't alert a box and the method can't change to the get. thank you.
Change onchange="selectSearch(select)"
to onchange="selectSearch(this)"
and put the select
in the form
tag
<select class="search_l" onchange="selectSearch(select)">
What is happening here? You're passing in select
to the Javascript function, but this value is not defined.
Also, your Javascript code is missing a closing curly bracket.
精彩评论