I've been messing around with Javascript recently and I'm still a beginner. I've been trying to build a simple program which finds a specified string inside the text entered into the text field using regular expressions, but for some reason when I click the "Find" button it gives me the following error:
Uncaught TypeError: find is not a function
onclick http://192.168.178.20:62126/JavaScript/Findy/index.html:1
index.html:1:1
Here's my code:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Findy</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="script.js"></script>
<form action="">
<input type="text" id="toFind" placeholder="What do you wanna find?">
<input type="button" id="find" onclick="find()" value="Find"></input>
<textarea name="textToSearch" id="textToSearch" cols="30" rows="10" placeholder="Enter your text"></textarea>
</form>
</body>
</html>
function find() {
var text=document.getElementById("textToSearch").value;
var word=document.getElementById(toFind).value;
var myRegex=/word/;
console.log(text.match(myRegex));
}