Button – calls a function to determine if the string in the textbox is found in the contents of the textarea. Naturally, message to the user if the string was found or not.
Those were the instructions given to follow, Im not sure exactly how to do this. Here is what I came up with, I keep getting this console error:
TypeError: document.getElementById(...) is null
file:///........program02javascript/program02script.js
Line 10line 10 : var SearchTerm = document.getElementById("text_box_1").value;
Here is my HTML:
<div id="requirement #2">
<h1>Requirement #2</h1>
<form>
Search For:
<input type="text" name="text_box_1">
<br>
</form>
<textarea id="text_area_3"></textarea>
<button type="button" id="button2" onclick="StringSearch()">Search</button>
</div>
Here is my Javascript:
function StringSearch() {
var SearchTerm = document.getElementById("text_box_1").value;
var TextSearch = document.getElementById("text_area_3").value;
if (TextSearch.match(SearchTerm) === "") {
alert("String Found. Search Complete");
} else {
alert("No Data found in Text Area");
}
}
How can I accomplish this task? I'm not sure I understand completely what to do. I was trying to find some example code but haven't come across anything that's been helpful.