JavaScript find and highlight text search button not working
<p>I'm using the script below to find and highlight text on a page. It works perfect if you enter the text and press the enter key but the weird thing is it doesn't work if you click the Find button, unless you first click somewhere on the page first. Its like when the search box is in focus or highlighted, the Find button won't work, even though it will work in focus with the Enter key. I tried removing the focus in CSS but no luck.</p>

<pre><code>&lt;script type="text/javascript"&gt;   
        var TRange=null;

        function findString (str) {
         if (parseInt(navigator.appVersion)&lt;4) return;
         var strFound;
         if (window.find) {

          // CODE FOR BROWSERS THAT SUPPORT window.find

          strFound=self.find(str);
          if (!strFound) {
           strFound=self.find(str,0,1);
           while (self.find(str,0,1)) continue;
          }
         }
         else if (navigator.appName.indexOf("Microsoft")!=-1) {

          // EXPLORER-SPECIFIC CODE

          if (TRange!=null) {
           TRange.collapse(false);
           strFound=TRange.findText(str);
           if (strFound) TRange.select();
          }
          if (TRange==null || strFound==0) {
           TRange=self.document.body.createTextRange();
           strFound=TRange.findText(str);
           if (strFound) TRange.select();
          }
         }
         else if (navigator.appName=="Opera") {
          alert ("Opera browsers not supported, sorry...")
          return;
         }
         if (!strFound) alert ("String '"+str+"' not found!")
         return;
        }
    &lt;/script&gt;
</code></pre>

<p>This is the search form</p>

<pre><code>&lt;form id="f1" name="f1" action="javascript:void()" onsubmit="if(this.t1.value!=null &amp;amp;&amp;amp; this.t1.value!='') parent.findString(this.t1.value);return false;"&gt;
    &lt;input type="text" id="t1" name="t1" value="text" size="20"&gt;
    &lt;input type="submit" name="b1" value="Find"&gt;
&lt;/form&gt;
</code></pre>

<p>I found the script at <a href="http://www.javascripter.net/faq/searchin.htm" rel="nofollow noreferrer">http://www.javascripter.net/faq/searchin.htm</a></p>