Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to 'force' server side for VBScript

Status
Not open for further replies.

Turkbear

Technical User
Mar 22, 2002
8,631
US
I have read in these forums that VBScript can be either client or server side - Since Netscape cannot handle VBScript that is client-side, how do I make the code run at the server?

Here is the page I need to work in IE or Netscape
It currently works great in IE....
( The VBScript code is from Adrian Forbes and I have included it in a simple test page with values from a drop-down list populated from a database...)
-----------------------------------------------------------
<%@ Language=VBScript %>
<html>
<body>
<div align=&quot;center&quot; >
<%
Dim objDC, objRS
' Create and establish data connection
Set objDC = Server.CreateObject(&quot;ADODB.Connection&quot;)
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30

'Code to connect to Oracle Warehouse
objDC.Open &quot;Provider=MSDAORA.1;Password=*****;User ID=*****;Data Source=whs1&quot;

SqlStrEmp = &quot;Select distinct empl_nm,empl_nbr empnbr from warehouse.hr_public order by empl_nm&quot;

Set RS1 = objDC.Execute(SqlStrEmp)

arrEmpData = RS1.GetRows()

RS1.Close
Set RS1 = Nothing

objDC.Close
Set objDC = Nothing
iRecFirstEmp = LBound(arrEmpData, 2)
iRecLastEmp = UBound(arrEmpData, 2)
iFieldFirstEmp = LBound(arrEmpData, 1)
iFieldLastEmp = UBound(arrEmpData, 1)

%>
<!-- Author: Adrian Forbes -->

<form name=frmTest METHOD=&quot;POST&quot; ACTION=&quot;SeeForm.asp&quot;>
<select size=&quot;1&quot; name=prompt0 ID=cboTest onKeyPress=&quot;return SelectText();&quot;>
<%
' Loop through the records (second dimension of the array)
For I = iRecFirstEmp To iRecLastEmp
' Continue until we get to the end of the recordset.

%>
<OPTION VALUE=&quot;<%=trim(arrEmpData(iFieldLastEmp,I)) %>&quot;><%=trim(arrEmpData(iFieldFirstEmp,I)) %> </OPTION>
<%
' Get next record

Next ' I
%>

</SELECT>
</select>
<INPUT type=&quot;hidden&quot; NAME=&quot;p1&quot; Value=&quot;&quot;>
<INPUT type=&quot;submit&quot; Value=&quot;Try It&quot; >
</form>
</div>

<script type=&quot;text/vbscript&quot; language=&quot;VBScript&quot; runat=&quot;server&quot;>
dim sBuffer ' This var stores the buffer of letters typed

function SelectText
dim objSelect, i, iLen

SelectText = False ' We need to return False to disable the
' SELECT's built-in functionality which is to
' select the first OPTION that begins with the
' key you pressed

sBuffer = sBuffer & Chr(window.event.keyCode) ' The keyCode is the ASCII value of the key you pressed
' so turn that into a character and add it to the buffer
iLen = len(sBuffer) ' We will be using this length a lot so store it in a local var for speed



set objSelect = document.frmTest.cboTest ' Get a handle on the SELECT object
for i = 0 to objSelect.Options.length - 1 ' Loop through each OPTION
if strcomp(left(objSelect.Options(i).Text, iLen), sBuffer, 1) = 0 then ' Test if the OPTION's Text starts with
' document.all(&quot;BestMatch&quot;).innerText = objSelect.Options(i).Text
document.frmTest.p1.value = objSelect.Options(i).Text ' the same letters as the buffer
objSelect.SelectedIndex = i ' If it does we want to select it

exit function ' Then exit the function
end if
next

sBuffer = &quot;&quot; ' If the code gets this far there is nothing in the SELECT
' that matches the buffer so reset it allowing the user
' to type new letters

end function
</script>

</body>
</html>
--------------------------------------------------------
Thanks in advance for helping a newbie understand what's going on...[bigears]


 
What you have here is an ASP page. It just happens to USE VBscript.

ASP can only run server-side, so IE/Netscape makes little difference except for the HTML emitted by the page.

If Netscrape is having trouble, it must be some detail in the HTML the processing of this page at the server creates and sends back to the browser.

I'd start by hitting the page and doing a &quot;view source&quot; to see what might be wrong. Then the ASP code will be &quot;peeled away&quot; so the trouble will be easier to spot.
 
Thanks for the tip..I did that and no obvious differences appear :

Here is the ( shortened ) 'View Source' from netscape which does not work ( is has the standard drop-down list behavior):
<html>
<body>
<div align=&quot;center&quot; >

<!-- Author: Adrian Forbes -->

<form name=frmTest METHOD=&quot;POST&quot; ACTION=&quot;SeeForm.asp&quot;>
<select size=&quot;1&quot; name=prompt0 ID=cboTest onKeyPress=&quot;return SelectText();&quot;>

<OPTION VALUE=&quot;00083545&quot;>Aaker,Dennis Wayne </OPTION>

<OPTION VALUE=&quot;01010317&quot;>Aamodt,Jeanne W </OPTION>

<OPTION VALUE=&quot;00170380&quot;>Aamodt,Lawrence Gerald </OPTION>

<OPTION VALUE=&quot;00432570&quot;>Aamot,James P </OPTION>

<OPTION VALUE=&quot;00084303&quot;>Aanenson,Alan N </OPTION>

<OPTION VALUE=&quot;00623908&quot;>Aarre,Darrin M </OPTION>

<OPTION VALUE=&quot;00260452&quot;>Aarre,Dean R </OPTION>

<OPTION VALUE=&quot;00265581&quot;>Aase,Brian Dale </OPTION>

<OPTION VALUE=&quot;01061416&quot;>Aasum,Christopher M </OPTION>

<OPTION VALUE=&quot;00099100&quot;>Aasum,Michael D </OPTION>

<OPTION VALUE=&quot;00168204&quot;>Abbe,Giles J </OPTION>

<OPTION VALUE=&quot;00504001&quot;>Abbott,Kevin E </OPTION>

<OPTION VALUE=&quot;00226981&quot;>Abear,Dale D </OPTION>

<OPTION VALUE=&quot;01041261&quot;>Abel,Elizabeth Jean </OPTION>

<OPTION VALUE=&quot;01033272&quot;>Abel,Jerome A </OPTION>

<OPTION VALUE=&quot;01042550&quot;>Abernathy,Jennifer Lynn </OPTION>

<OPTION VALUE=&quot;01009802&quot;>Abfalter,Robert A </OPTION>

<OPTION VALUE=&quot;01036153&quot;>Abrahamson,David A </OPTION>

<OPTION VALUE=&quot;00297351&quot;>Abrahamson,Duane E </OPTION>
------------SKIPPED 5000 more in list for clarity ------------------------------
</SELECT>
</select>
<INPUT type=&quot;hidden&quot; NAME=&quot;p1&quot; Value=&quot;&quot;>
<INPUT type=&quot;submit&quot; Value=&quot;Try It&quot; >
</form>
</div>

<script type=&quot;text/vbscript&quot; language=&quot;VBScript&quot;>

dim sBuffer ' This var stores the buffer of letters typed

function SelectText
dim objSelect, i, iLen

SelectText = False ' We need to return False to disable the
' SELECT's built-in functionality which is to
' select the first OPTION that begins with the
' key you pressed

sBuffer = sBuffer & Chr(window.event.keyCode) ' The keyCode is the ASCII value of the key you pressed
' so turn that into a character and add it to the buffer
iLen = len(sBuffer) ' We will be using this length a lot so store it in a local var for speed



set objSelect = document.frmTest.cboTest ' Get a handle on the SELECT object
for i = 0 to objSelect.Options.length - 1 ' Loop through each OPTION
if strcomp(left(objSelect.Options(i).Text, iLen), sBuffer, 1) = 0 then ' Test if the OPTION's Text starts with
document.frmTest.p1.value = objSelect.Optionsi).Text ' the same etters as the buffer
objSelect.SelectedIndex = i ' If it does we want to select it

exit function ' Then exit the function
end if
next

sBuffer = &quot;&quot; ' If the code gets this far there is nothing in the SELECT
' that matches the buffer so reset it allowing the user
' to type new letters

end function

</script>

</body>
</html>

-----------
Here is it from IE ( which works as I wanted..the more letters you type, the closer you get to the name you want)
<html>
<body>
<div align=&quot;center&quot; >

<!-- Author: Adrian Forbes -->

<form name=frmTest METHOD=&quot;POST&quot; ACTION=&quot;SeeForm.asp&quot;>
<select size=&quot;1&quot; name=prompt0 ID=cboTest onKeyPress=&quot;return SelectText();&quot;>

<OPTION VALUE=&quot;00083545&quot;>Aaker,Dennis Wayne </OPTION>

<OPTION VALUE=&quot;01010317&quot;>Aamodt,Jeanne W </OPTION>

<OPTION VALUE=&quot;00170380&quot;>Aamodt,Lawrence Gerald </OPTION>

<OPTION VALUE=&quot;00432570&quot;>Aamot,James P </OPTION>

<OPTION VALUE=&quot;00084303&quot;>Aanenson,Alan N </OPTION>

<OPTION VALUE=&quot;00623908&quot;>Aarre,Darrin M </OPTION>

<OPTION VALUE=&quot;00260452&quot;>Aarre,Dean R </OPTION>

<OPTION VALUE=&quot;00265581&quot;>Aase,Brian Dale </OPTION>

<OPTION VALUE=&quot;01061416&quot;>Aasum,Christopher M </OPTION>

<OPTION VALUE=&quot;00099100&quot;>Aasum,Michael D </OPTION>

<OPTION VALUE=&quot;00168204&quot;>Abbe,Giles J </OPTION>

<OPTION VALUE=&quot;00504001&quot;>Abbott,Kevin E </OPTION>

<OPTION VALUE=&quot;00226981&quot;>Abear,Dale D </OPTION>

<OPTION VALUE=&quot;01041261&quot;>Abel,Elizabeth Jean </OPTION>

<OPTION VALUE=&quot;01033272&quot;>Abel,Jerome A </OPTION>

<OPTION VALUE=&quot;01042550&quot;>Abernathy,Jennifer Lynn </OPTION>

<OPTION VALUE=&quot;01009802&quot;>Abfalter,Robert A </OPTION>

<OPTION VALUE=&quot;01036153&quot;>Abrahamson,David A </OPTION>

<OPTION VALUE=&quot;00297351&quot;>Abrahamson,Duane E </OPTION>

<OPTION VALUE=&quot;01026769&quot;>Abu-shaqra,Diaa F. </OPTION>

<OPTION VALUE=&quot;00483694&quot;>Ackerman,Duane F </OPTION>

<OPTION VALUE=&quot;00354253&quot;>Adair,Ralph L </OPTION>

<OPTION VALUE=&quot;00430858&quot;>Adam,John P </OPTION>

<OPTION VALUE=&quot;00279102&quot;>Adamez,Lydia </OPTION>

<OPTION VALUE=&quot;01038464&quot;>Adams,Angela R </OPTION>

<OPTION VALUE=&quot;01035997&quot;>Adams,Billy O </OPTION>

<OPTION VALUE=&quot;00421412&quot;>Adams,Cynthia Flynn </OPTION>

<OPTION VALUE=&quot;00346708&quot;>Adams,James L </OPTION>

<OPTION VALUE=&quot;01034363&quot;>Adams,Jerome </OPTION>

<OPTION VALUE=&quot;00557686&quot;>Adams,Linda L </OPTION>

<OPTION VALUE=&quot;01030391&quot;>Adamsky,Steven J </OPTION>
----------------- SKIPPED 5000m More ----------------------------------------


</SELECT>
</select>
<INPUT type=&quot;hidden&quot; NAME=&quot;p1&quot; Value=&quot;&quot;>
<INPUT type=&quot;submit&quot; Value=&quot;Try It&quot; >
</form>
</div>

<script type=&quot;text/vbscript&quot; language=&quot;VBScript&quot;>
dim sBuffer ' This var stores the buffer of letters typed

function SelectText
dim objSelect, i, iLen

SelectText = False ' We need to return False to disable the
' SELECT's built-in functionality which is to
' select the first OPTION that begins with the
' key you pressed

sBuffer = sBuffer & Chr(window.event.keyCode) ' The keyCode is the ASCII value of the key you pressed
' so turn that into a character and add it to the buffer
iLen = len(sBuffer) ' We will be using this length a lot so store it in a local var for speed



set objSelect = document.frmTest.cboTest ' Get a handle on the SELECT object
for i = 0 to objSelect.Options.length - 1 ' Loop through each OPTION
if strcomp(left(objSelect.Options(i).Text, iLen), sBuffer, 1) = 0 then ' Test if the OPTION's Text starts with
document.frmTest.p1.value = objSelect.Options(i).Text ' the same letters as the buffer
objSelect.SelectedIndex = i ' If it does we want to select it

exit function ' Then exit the function
end if
next

sBuffer = &quot;&quot; ' If the code gets this far there is nothing in the SELECT
' that matches the buffer so reset it allowing the user
' to type new letters

end function
</script>

</body>
</html>

--------------
Spot anything?

Thanks again
 
Anything with the following will not work in Netscape:

<script type=&quot;text/vbscript&quot; language=&quot;VBScript&quot;>

You need to use Javascript for script functions that are written on the HTML pages inside script tags.

 
That is what is confusing me[sad]..If the scripts run server-side why does it matter which browser gets the page..
( I realise that the script is in the body and is interactive, could that be why the script must run client-side?)

Thanks for the quick response..This is a very active forum..

 
<script type=&quot;text/vbscript&quot; language=&quot;VBScript&quot;> doesn't run server side, and is used for processing information added to the page after it's built, on the client side. Any script that has to be written on the page as script is client side, and has to be Javascript. In other words, if you have anything that reads user input, it's client side, and can't be VBSCript. Your function SelectText is written run on the client side, and in fact HAS to be run client-side because it isn't called without user input. You can't run that kind of function server-side, so you have to convert it to Javascript to be compatible with Netscape.
 
Thanks..That's the reluctant conclusion I have come to..
Now the work begins, since I am not sure how to code VB functions like that in JavaScript..( Oh Well, another learning opportunity....)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top