enjoylife
enjoylife

Reputation: 5469

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.

Upvotes: -1

Views: 71

Answers (2)

w35l3y
w35l3y

Reputation: 8783

Change onchange="selectSearch(select)" to onchange="selectSearch(this)" and put the select in the form tag

Upvotes: 2

Matt Healy
Matt Healy

Reputation: 18531

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

Upvotes: 1

Related Questions