JHalstead
asked on
VBScript to Javascript
I have been told that any VBScript can be transformed into Javascript. I have this page in VBScript that needs to be converted…
[code]
<%@ Language=VBScript %>
<html>
<head>
<title>Search</title>
<script>
function viewHelp(sourcefile, w, h) {
winPop = window.open(sourcefile,"He lp","width ="+w+",hei ght="+h+", scrollbars =yes, screenX=75,screenY=75,left =75,top=75 ");
}
</script>
</head>
<body bgcolor="#ffffff">
<div align="center">
<table>
<tr><td class="tdWhite"><a href="javascript:viewHelp( 'instructi ons.htm', 425, 400);">Instructions</a></t d></tr>
</table>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3"><img src="Logo.jpg"></td>
</tr>
<tr>
<td class="tdWhite" width="710" height="264" border="0" align="center">
<table>
<tr>
<td class="tdWhite" valign="top">
<%
Dim conn, engine, i
Set engine = CreateObject("ActiveX.Sear chEngine")
Dim Regions
Regions = engine.GetRegions
Dim RegionID
If Request("RegionID").Count > 0 Then
RegionID = CLng( Request("RegionID")(1))
Else
RegionID = Regions(0,0)
End If
engine.HugeResultAllow = True
%>
<form id="mainForm" action="search.asp" method="get">
<p class="small">Select a topic to search: <a href="javascript:viewHelp( 'topic.htm ', 425, 200);">?</a><br>
<select id="RegionID" name="RegionID" onchange="mainForm.submit( )">
<%
For i = LBound(Regions, 2) To UBound(Regions, 2)
%>
<option value="<%=Regions(0,i)%>" <%If Regions(0,i) = RegionID Then Response.Write "selected"%>><%=Regions(1, i)%></opti on>
<%
Next
%>
</select><br>
<p class="small">Choose a context to search: <a href="javascript:viewHelp( 'context.h tm', 425, 300);">?</a><br>
<select size="5" id="tags" name="tags" multiple>
<%
Dim Rules
Rules = engine.GetRules(CLng(Regio nID))
For i = LBound(Rules, 2) To UBound(Rules, 2)
%>
<option value="<%=Rules(0,i)%>" selected><%=Rules(1,i)%></ option>
<%
Next
%>
</select><br>
<p class="small">Enter a search string: <a href="javascript:viewHelp( 'boolean.h tm', 425, 500);">?</a><br>
<input id="q" name="q" value="<%=Server.HTMLEncod e("" & Request("q"))%>">
<input type="submit" name="action" value="Search"><br>
<input type="checkbox" name="hl" <%If Request("hl").Count > 0 Then Response.Write "checked"%>> Word Highlighting
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
<% If Request("q").Count > 0 And Request("action").Count > 0 Then
Dim SelectedRules
SelectedRules = ""
For i = 1 To Request("tags").Count
SelectedRules = SelectedRules & "," & Request("tags")(i)
Next
engine.SelectedRules = Mid(SelectedRules, 2)
Set Session("SearchResult") = Nothing
If engine.Search(Request("q") (1)) Then
Dim Documents
Set Documents = engine.result
Set Session("SearchResult") = Documents
If Request("hl").Count > 0 Then Session("SearchWords") = Join(engine.WorkWords, "-") Else Session("SearchWords") = ""
Dim entry, DocList
Set DocList = Documents.selectNodes("//d ocument")
If DocList.length < 1 Then
%>
<hr width="722">
<span class="intro"><b>No results</b></span>
<%
Else
%>
<span class="intro"><b>Results</ b></span>
<hr width="722">
<table width="722">
<tr><th></th><th>Document< /th><th>Co ntext(s)</ th></tr>
<%
For j = 0 To DocList.length - 1
Set entry = DocList(j)
Dim tags, s
Set tags = entry.selectNodes("rules/r ule")
s = ""
For k = 0 To tags.length - 1
s = s & "," & tags(k).selectSingleNode(" descriptio n").text
Next
%>
<tr>
<td align="right"><%=j+1%></td ><td><a title="Document and path where string is located. If clicked, will display document." href="show.asp?doc=<%=entr y.selectSi ngleNode(" url").text %>&wor ds=<%=Sess ion("Searc hWords")%> "><%=entry .selectSin gleNode("t itle").tex t%></a></t d>
<td> <a title="A preview of the context(s) in which the string was found. If clicked, displays a list of links according to each context." href="showdetails.asp?id=< %=entry.ge tAttribute ("id")%>"> <%= Mid(s,2) %></a></td>
</tr>
<%
Next
%>
</table>
<%
End If
Else
%>
<p class="intro"><b>Error: <%=engine.ErrorReason%></b ></p>
<%
End If
%>
<%
End If
%>
</div>
</body>
</html>
[/code]
[code]
<%@ Language=VBScript %>
<html>
<head>
<title>Search</title>
<script>
function viewHelp(sourcefile, w, h) {
winPop = window.open(sourcefile,"He
}
</script>
</head>
<body bgcolor="#ffffff">
<div align="center">
<table>
<tr><td class="tdWhite"><a href="javascript:viewHelp(
</table>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3"><img src="Logo.jpg"></td>
</tr>
<tr>
<td class="tdWhite" width="710" height="264" border="0" align="center">
<table>
<tr>
<td class="tdWhite" valign="top">
<%
Dim conn, engine, i
Set engine = CreateObject("ActiveX.Sear
Dim Regions
Regions = engine.GetRegions
Dim RegionID
If Request("RegionID").Count > 0 Then
RegionID = CLng( Request("RegionID")(1))
Else
RegionID = Regions(0,0)
End If
engine.HugeResultAllow = True
%>
<form id="mainForm" action="search.asp" method="get">
<p class="small">Select a topic to search: <a href="javascript:viewHelp(
<select id="RegionID" name="RegionID" onchange="mainForm.submit(
<%
For i = LBound(Regions, 2) To UBound(Regions, 2)
%>
<option value="<%=Regions(0,i)%>" <%If Regions(0,i) = RegionID Then Response.Write "selected"%>><%=Regions(1,
<%
Next
%>
</select><br>
<p class="small">Choose a context to search: <a href="javascript:viewHelp(
<select size="5" id="tags" name="tags" multiple>
<%
Dim Rules
Rules = engine.GetRules(CLng(Regio
For i = LBound(Rules, 2) To UBound(Rules, 2)
%>
<option value="<%=Rules(0,i)%>" selected><%=Rules(1,i)%></
<%
Next
%>
</select><br>
<p class="small">Enter a search string: <a href="javascript:viewHelp(
<input id="q" name="q" value="<%=Server.HTMLEncod
<input type="submit" name="action" value="Search"><br>
<input type="checkbox" name="hl" <%If Request("hl").Count > 0 Then Response.Write "checked"%>> Word Highlighting
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
<% If Request("q").Count > 0 And Request("action").Count > 0 Then
Dim SelectedRules
SelectedRules = ""
For i = 1 To Request("tags").Count
SelectedRules = SelectedRules & "," & Request("tags")(i)
Next
engine.SelectedRules = Mid(SelectedRules, 2)
Set Session("SearchResult") = Nothing
If engine.Search(Request("q")
Dim Documents
Set Documents = engine.result
Set Session("SearchResult") = Documents
If Request("hl").Count > 0 Then Session("SearchWords") = Join(engine.WorkWords, "-") Else Session("SearchWords") = ""
Dim entry, DocList
Set DocList = Documents.selectNodes("//d
If DocList.length < 1 Then
%>
<hr width="722">
<span class="intro"><b>No results</b></span>
<%
Else
%>
<span class="intro"><b>Results</
<hr width="722">
<table width="722">
<tr><th></th><th>Document<
<%
For j = 0 To DocList.length - 1
Set entry = DocList(j)
Dim tags, s
Set tags = entry.selectNodes("rules/r
s = ""
For k = 0 To tags.length - 1
s = s & "," & tags(k).selectSingleNode("
Next
%>
<tr>
<td align="right"><%=j+1%></td
<td> <a title="A preview of the context(s) in which the string was found. If clicked, displays a list of links according to each context." href="showdetails.asp?id=<
</tr>
<%
Next
%>
</table>
<%
End If
Else
%>
<p class="intro"><b>Error: <%=engine.ErrorReason%></b
<%
End If
%>
<%
End If
%>
</div>
</body>
</html>
[/code]
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, the truth of the matter is, this script works fine on an ASP enabled server, but I was tasked to create a DHTML version that would not need a server to run. I technically don't know if this is possible but I think it would be…
Now that was what I assumed.
And the answer is: it would be possible, but only on that one machine where the server is running AND only when the page is invoked locally on that machine, not trough a web server.
The reason is that it is not possible to examine anything on server side what is not on client side.
Therefore you can not run a full text search on client side which does a lookup of server side repository.
Additionally you can not instantiate an ActiveX module from a web server page to lookup client side objects.
Sorry for the bad news.
And the answer is: it would be possible, but only on that one machine where the server is running AND only when the page is invoked locally on that machine, not trough a web server.
The reason is that it is not possible to examine anything on server side what is not on client side.
Therefore you can not run a full text search on client side which does a lookup of server side repository.
Additionally you can not instantiate an ActiveX module from a web server page to lookup client side objects.
Sorry for the bad news.
I would agree - server-side code (VBScript) isn't interchangable with client-side code (JavaScript). The VBScript runs code on the webserver (which has to allow it), and can't access the client.
Client-side code runs on your local browser and can't access the server. You need to be able to run code on ther server in order to use your ActiveX control.
Client-side code runs on your local browser and can't access the server. You need to be able to run code on ther server in order to use your ActiveX control.
ASKER
Ok, now we are getting somewhere.
In the DHTML version there would be no server. Everything would be contained on a CD or in an EXE.
If this code cannot be converted to be able to do this please tell me how I can close/delete this topic...
In the DHTML version there would be no server. Everything would be contained on a CD or in an EXE.
If this code cannot be converted to be able to do this please tell me how I can close/delete this topic...
ASKER