Hello, I'm trying to make a simple search with Javascript to search a form, I need to pull the index of my search term. This is what I have so far, but I'm seriously having issues. Any help is appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Form</title>
<script language="JavaScript" type=text/javascript>
function search(sub, string) {
    var where=str.indexOf(toSearch);
      alert(where);
if(where =="") ||(where == null))
    {
   alert("The string was not found");
   }    
}
//-->
</script>
</head>
<body>
<h3>CIW JavaScript Specialist</h3>
<hr />
<form name="myForm">
<p>
<strong>Look for:</strong>
<input type="text" name="what" size="20" />
</p>
<p>
<strong>in this string:</strong>
<textarea name="toSearch" rows="4" cols="30" wrap="virtual">
<body>
<h3>CIW JavaScript Specialist</h3>
<hr />
<form name="myForm">
<p>
<strong>Look for:</strong>
<input type="text" name="what" size="20" />
</p>
<p>
<strong>in this string:</strong>
<textarea name="toSearch" rows="4" cols="30" wrap="virtual">
</textarea>
</p>
<p>
<input type="button" value="Search" onclick="search(myForm.what.value, myForm.toSearch.value);" />
</p>
</form>
</body>
</html>

I'm seriously having issues

Issues with what? Specify what you want and what the problem is.

The indexOf() function for string or array returns -1 if not found, not an empty string or null...

Your major issue should be with the browser is IE (not sure if the current version still has this problem) because it does not have the build-in indexOf() function. Is that what you are asking for as well?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.