Webmaster Forum

Go Back   Webmaster Forum > Scripting/Programming & Debugging > ASP & VBScript Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

ASP & VBScript Forum Need help from a webmaster with ASP or VBScript, you may ask in this forum?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-15-2007, 05:15 AM
sharjeel sharjeel is offline
Junior Member
 
Join Date: May 2007
Posts: 1
sharjeel is an unknown quantity at this point
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default finding certain text in html page+vbsript

I am new to vbscript.I have basic knowledge of vbscripting. Now I have to implement a code in vbscript which will get input (search string) form the user on a webpage and highlight the matching string on this page. Can anyone provide me any sample code or hint in this regard.

Thanks in advance.

Best regards,
Sharjeel
NCP

Last edited by sharjeel : 05-15-2007 at 06:11 AM. Reason: Problem described in detail.
Reply With Quote

This ad is part of our Revenue Sharing program
  #2 (permalink)  
Old 05-15-2007, 02:26 PM
ALL's Avatar
ALL ALL is offline
Senior Member
 
Join Date: Oct 2006
Location: Sturgis, SD
Posts: 145
ALL is on a distinguished road
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default

Here is a simple VBScript that should do what you are saying, but to keep some problems from occuring the searchable text must be in a <SPAN> with the class name of "searchMe" (ie: <span class="searchMe">searchable text</span>)

anyway try playing around with it:
HTML Code:
<html> <head> <script type="text/vbscript"> OrigBody = "" Function findAndHighlight(strFind) If OrigBody = "" Then OrigBody = document.body.innerHTML End If Set myRegExp = New RegExp myRegExp.Global = True myRegExp.Pattern = "(" + strFind + ")" 'Uncomment this to search with case sensative' myRegExp.IgnoreCase = True For Each mySpan In document.getElementsByTagName("span") If mySpan.className = "searchMe" Then mySpan.innerHTML = myRegExp.Replace(mySpan.innerHTML, "<span style=" + """" + "background-color:yellow" + """" + ">$1</span>") End If Next End Function Function resetBody() document.body.innerHTML = OrigBody OrigBody = "" End Function </script> </head> <body> <span class="searchMe">Here is some text, that is used to test code.</span><br /> <input type="text" name="lookFor" id="lookFor" /> <input type="button" onclick="findAndHighlight(document.getElementById('lookFor').value)" value="Search" /> <input type="button" onclick="resetBody()" value="Reset" /> </body> </html>
Btw... the reason the color coding is all funny looking is because it is color coded for javascript
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Colored banner across entire page width? fadetoblackmm HTML Forum 1 04-14-2007 03:47 AM


All times are GMT. The time now is 04:59 AM.


Creative Commons License
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30