Solved

VBScript to Javascript

Posted on 2003-12-08
8
575 Views
Last Modified: 2012-05-04
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
Comment
Question by:JHalstead
  • 3
  • 2
  • 2
8 Comments
 
LVL 6

Assisted Solution

by:pillbug22
pillbug22 earned 250 total points
ID: 9906455
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
 

Author Comment

by:JHalstead
ID: 9908223
Thanks pillbug, that will help me learn in the future, but I need that translated asap...
0
 
LVL 2

Accepted Solution

by:
PurplePerls earned 250 total points
ID: 9912124
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:JHalstead
ID: 9912624
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
 
LVL 2

Expert Comment

by:PurplePerls
ID: 9912795
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
 
LVL 6

Expert Comment

by:pillbug22
ID: 9912890
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
 

Author Comment

by:JHalstead
ID: 9950732
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countXY challenge 28 117
while loop over for loop 7 81
copyEvens challenge 6 64
bunnyEars2 challenge 6 71
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now