I've been trying to get this code to work:
<!DOCTYPE html>
<html>
<body>
<input name="paragraph" id="paragraph" value="Paste your paragraph here!" style="width: 800px; height: 100px;"><br>
<input name="search" id="search" value="(Case sensitive) Text to search for" style="width: 400px;"><br>
<button type="button" onclick="myFunction()">Find text</button><br>
<script>
function myFunction() {
text = document.getElementById("paragraph");
var textSearch = document.getElementById("search");
var hits = [];
for(var i = 0; i < text.length; i++) {
if(text[i] == "J"){
for (var j = i; j < (textSearch.length + i); j++) {
hits.push(text[j]);
}
if (hits === 0) {
alert('Your name isn't here')
} else {
alert(hits);
}
}
</script>
</body>
</html>
Basically, what it's trying to do is for the user to enter a paragraph or big chunk of text into the top box, then some text they're trying to search for in the lower box. Then hit a button and it displays where in the code that it is (by telling the user how many characters it went through, until it hit what they were searching for). If you could improve it, or show me something from scratch that would be better!
text.indexOf(textSearch)textparameter. This should bevar text = ...;