-1
<input id="ask" type="text">
<input id="submit" type="button" onclick="askQuestion">
<script>
    function askQuestion {
        if (document.getElementById('ask').value /*contains*/ "time"{
            /*tell time*/}
    }
</script>

Okay so I have something similar to the code above. The only thing I want to know is how do I check for if the "ask" textbox contains the word time? Thank you in advance!

Dr. Owning
  • 171
  • 2
  • 14
  • It's a string: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf – Marc B Apr 08 '15 at 16:43
  • You could use `document.getElementById('ask').value.indexOf("time") >= 0`, or you could use a regular expression `/time/.test(document.getElementById('ask').value)`. – jwatts1980 Apr 08 '15 at 16:44

1 Answers1

-1

You can use bool contains = document.getElementById('ask').value.indexOf("time") > -1

   function askQuestion {
        if (document.getElementById('ask').value.indexOf("time") > -1) {
            /*tell time*/}
    }
enb081
  • 3,831
  • 11
  • 43
  • 66