Filtering an HTML table
<html>

				<script language="VBScript">
				Sub filterResults()
					Dim searchBox
					Set searchBox = Document.forms("searchBoxID")

					For Each subInstance In document.GetElementsByTagName("tr")
						If Not subInstance.OuterHTML.Contains(searchBox.filterTXT.Value) Then
							subInstance.style = "display:none"
						End If
					Next

				End Sub
				</script>
				
								<form id="searchBoxID" 
onsubmit="filterResults(); return false;" language="jscript">
Filter results: <input name="filterTXT" type="text" size="2"/><input name="searchBTN" type="Submit" value="Go">
<table border=1>
<th>
Row One
</th>
<th>
Row Two
</th>
<th>
Row Three
</th>
<tr>
<td>
Stuff
</td>
<td>
Things
</td>
<td>
Items
</td>
</tr>
<tr>
<td>
Possessions
</td>
<td>
Objects
</td>
<td>
Things
</td>
</tr>
</table>

</html>
I am trying to filter this table by using a search box. If the keyword doesn't match anything in a row, that row is hidden. Problem is nothing gets hidden.



May 27th, 2015 2:30am

Start by learning how to build a web page.  Here is a good resource: http://www.w3schools.com/

You appear to be trying ot mix jscript and vbscript. I don't think that is what you want to do.

Free Windows Admin Tool Kit Click here and download it now
May 27th, 2015 3:24am

This will point you in the correct direction:

Put the following in a file with an HTA extension and run it.

<html>

<script language="VBScript">
	Sub filterResults()
		
		For Each row In tbl1.Rows
			row.style.display="none"
		Next
		
	End Sub
</script>
<body>
Filter results:<input name="filterTXT" type="text" size="2"/><input type="button" value="Go" onclick="filterResults">
<table id="tbl1" border=1>
	<tr><th>Column One</th><th>Column Two</th><th>Column Three</th></tr>
	<tr><td>Stuff</td><td>Things</td><td>Items</td></tr>
	<tr><td>Possessions</td><td>Objects</td><td>Things</td></tr>
</table>
</body>
</html>

Click the "Go" button and watch what happens.

May 27th, 2015 3:40am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics