title: How to make javascript toggle button?
body: <p>I have this code but it doesn't work:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;button id="btn_search"&gt;Search&lt;/button&gt;
  &lt;input id="srh" type="search"&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>var btnSearch = document.getElementById("btn_search");
  var search = document.getElementById("srh");
  
  if (document.addEventListener) {
     btnSeach.addEventListener('click',activeSearch);
  } else if (document.attackEvent) {
     btnSearch.attackEvent('onclick',activeSearch);
  }
  
  function activeSearch (event) {
    event.preventDefault();
    if (search.style.width == '0') {
      search.style.width = '14.8em';
      search.style.opacity = '1';
  } else if (search.style.width == '14.8em') {
      search.style.width = '0';
      search.style.opacity = '0';
  }
  </code></pre>
  
  <p>I need a toggle button
  What should I do?</p>