Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS needed to search for string in text

Status
Not open for further replies.

PaulShotgun

Technical User
Mar 7, 2002
10
GB
I need some JavaScript to go inside an HTML page that's generated by a CGI file that basically says 'If the text string 'blah blah' is included in this page, then display a dialog box'.

Is this very easy to do?

Could someone give me the code for this plase as I am a JavaScript newbie and haven't a clue where to start! Thanks!
 
Is this the kind of thing you're talking about?

Code:
<HTML>
<HEAD>
<SCRIPT>
function showBox(searchString)
{
 var bodyText = document.body.innerHTML;
 if(bodyText.indexOf(searchString) != -1)
  alert(&quot;'&quot;+searchString+&quot;' found on page!&quot;);
}//end showBox(var)
</SCRIPT>
</HEAD>
<BODY ONLOAD=showBox(&quot;KLMNOP&quot;)>
ABC DEFG HIJ KLMNOP, QRST UV WXYZ.
</BODY>
</HTML>

I don't know anything about CGI, so I'm assuming you can hardcode the text-of-interest into the showBox function call in the HTML as above.

'hope this helps.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top