- user enters 2 strings
- use a regular expression to search for the second string within the first string.
Those are my directions to follow. I was not told what to do with the search results so I decided to use the exec() method to display the results.
My code does not display any results.
html:
<div id="string_search">
<h3>Requirement #1</h3>
<p>Enter a string in the first box. <br>
Enter a search term in the second box.<br>
Click the button to find the term.</p>
<textarea id="user_string" rows="4" cols="50" placeholder="Enter string (text) here."></textarea>
<form>
Enter Search Term:<input type="text" id="search_term" size="45"><br>
<input type="button" id="search_button" value="Search" onclick="SearchString()"><br>
</form>
<textarea id="search_results" placeholder="Results here..." rows="4" cols="30"></textarea>
</div>
javascript:
function SearchString(){
var user_string = document.getElementById("user_string").innerHTML;
var search_term = document.getElementById("search_term").value;
// regex to find all instances of search term
var re = new RegExp(search_term,"gi");
//use exec() to return matched text
var result = re.exec(user_string);
//display results in textarea "search_results"
document.getElementById("search_results").innerHTML = result;
}
I am not getting console errors, is my code not functional? maybe there's a spelling error im not seeing or similar. Been staring at this for awhile,