[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

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,"Help","width="+w+",height="+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('instructions.htm', 425, 400);">Instructions</a></td></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.SearchEngine")

        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)%></option>
<%
        Next
%>
</select><br>
<p class="small">Choose a context to search: <a href="javascript:viewHelp('context.htm', 425, 300);">?</a><br>
<select size="5" id="tags" name="tags" multiple>
<%
        Dim Rules
        Rules = engine.GetRules(CLng(RegionID))
        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.htm', 425, 500);">?</a><br>
<input id="q" name="q" value="<%=Server.HTMLEncode("" & Request("q"))%>">
&nbsp; <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("//document")
                       
                        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>Context(s)</th></tr>
<%
                                For j = 0 To DocList.length - 1
                                        Set entry = DocList(j)
                                        Dim tags, s
                                        Set tags = entry.selectNodes("rules/rule")
                                        s = ""
                                        For k = 0 To tags.length - 1
                                                s = s & "," & tags(k).selectSingleNode("description").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=<%=entry.selectSingleNode("url").text%>&amp;words=<%=Session("SearchWords")%>"><%=entry.selectSingleNode("title").text%></a></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=<%=entry.getAttribute("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]
0
JHalstead
Asked:
JHalstead
  • 3
  • 2
  • 2
2 Solutions
 
pillbug22Commented:
You can convert from VBScript to JScript (not JavaScript).  JScript and JavaScript are close, but not quite the same (JScript is MS's version, available to use for ASP scripting and Windows Scripting)

Most all of the functions, etc are identical between the two, but the sysntax is a little different.

MSDN: Scripting Laguages (articles, language refernce, etc)
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28001169

Language Refernce for JScript:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jslrfjscriptlanguagereference.asp
0
 
JHalsteadAuthor Commented:
Thanks pillbug, that will help me learn in the future, but I need that translated asap...
0
 
PurplePerlsCommented:
One important info is that your actual VB code is executed on server side.
Are you aware of the server side aspect, and why do you need on server side (*.asp) to run JavaScript?

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
JHalsteadAuthor Commented:
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…
0
 
PurplePerlsCommented:
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.
0
 
pillbug22Commented:
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.
0
 
JHalsteadAuthor Commented:
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...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now