title: Validation search field in javascript
body: <p>I have this code, but I just can not make it work. What according to you is the problem?</p>
  
  <pre><code>&lt;div class="box-search"&gt;
  &lt;form action="" method="get" onsubmit="return doSearch('search-form','text_cautat');" id="search-form"&gt;
      &lt;input type="text" name="s" class="search-field" id="text_cautat" value="" maxlength="100" placeholder="Cauta" /&gt;
      &lt;select class="search-cat select-menu" name="categorie" id="cat_cautare"&gt;
          &lt;option value="0"&gt;Toate&lt;/option&gt;
          &lt;option value="211"&gt;Accesorii GSM&lt;/option&gt;
          &lt;option value="406"&gt;Laptopuri &amp;amp; Tablete&lt;/option&gt;
          &lt;option value="193"&gt;Componente PC&lt;/option&gt;
          &lt;option value="416"&gt;Periferice&lt;/option&gt;
          &lt;option value="1364"&gt;Gaming PC &amp;amp; Console&lt;/option&gt;
          &lt;option value="192"&gt;Foto &amp;amp; Video&lt;/option&gt;
          &lt;option value="233"&gt;Electronice&lt;/option&gt;
          &lt;option value="219"&gt;Auto&lt;/option&gt;
          &lt;option value="1378"&gt;Telefoane&lt;/option&gt;
      &lt;/select&gt;
      &lt;input type="button" value="Cerca" onclick="return doSearch('search-form','text_cautat');" class="search-button" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p>and JS:</p>
  
  <pre><code>function doSearch(id_form, id_camp) {
  var search_string = $(id_camp).value;
  
  //trim
  search_string = trim(search_string);
  
  var search_form = $(id_form);
  
  if (search_string.length &lt; 3) {
      alert("Minimo 3 caratteri!");
      return false;
  } else {
      var cuvinte_split = search_string.split(" ");
  
      search_string = search_string.replace(/-/g, "_");
      search_string = search_string.replace(/[^A-Za-z0-9_.]/g, "-");
      search_form.action = "http://www.website.com/cerca/" + search_string;
          search_form.submit();
          return true;
      }
  }
  
  function trim(str, chars) {
      return ltrim(rtrim(str, chars), chars);
  }
  
  function ltrim(str, chars) {
      chars = chars || "\\s";
      return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
  }
  
  function rtrim(str, chars) {
      chars = chars || "\\s";
      return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
  }
  </code></pre>
  
  <p>The script should allow the searching have been entered only if at least three characters. But it does not work.</p>
  
  <p><a href="http://jsfiddle.net/ZP8R9/" rel="nofollow">http://jsfiddle.net/ZP8R9/</a></p>