title: javascript: input form requires specific word
body: <p>i'm having a hard time validating a text field that must have a specific word in it. For example i have typed a test page that requires the user to type 'hello' if they don't there will be an alert.</p>
  
  <p>I have tried using indexOf, but it fail to work in my case. May i ask what went wrong? and is there any other way of validating such scenario? I would prefer to use vanilla javascript if possible. Thanks.</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript"&gt;
              function checkText()
              {
              var text1 = document.getElementById("intro").value;
              var text2 = 'hello';
  
              if(text1.indexOf(text2) &gt; -1){
                  alert("Say hello");
                  return false;
              }else{
                  alert("Okay!");
              }
          }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          Introduce yourself &lt;input type="text" name="intro" id="intro"&gt; &lt;input type="button" value="Click" onClick="checkText()"&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>