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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert VBScript to JavaScript

Status
Not open for further replies.

Lambro

Programmer
Aug 22, 2001
258
US
One the top of the page I'm trying to add some code is:
<%@language="javascript"%>


The code I'm trying to add is:

<%
if not session("userinfo")="" then
%>

xxxx


<%
else
response.redirect "%>
<%end if%>



It keeps erroring out by giving me the following error:

Error Type:
Microsoft JScript compilation (0x800A03ED)
Expected '('


Is there a way to check a session variable and redirect to a page if there's no session variable

When I use this code in my asp page with <%@LANGUAGE="VBSCRIPT"%> at the top, it works fine but I need it to work with <%@language="javascript"%> at the top.


Can someone convert my VBScript to JavaScript???
 
I've not tried this (no ASP host at the mo) but it might work ;o). Try changing this:

Code:
<%
if not session("userinfo")="" then
%>
xxxx
<%
else
response.redirect "[URL unfurl="true"]http://www.advancedcontrolsolutions.com/sessionexpired.asp"[/URL]
%>
<%end if%>

to this:

Code:
<%
	if (session('userinfo') != '') {
%>
xxxx
<%
	} else {
		response.redirect('[URL unfurl="true"]http://www.advancedcontrolsolutions.com/sessionexpired.asp');[/URL]
	}
%>

If that fails, it is possible that you might need to change this:

Code:
session('userinfo')

into this:

Code:
session('userinfo').value

although I'm not 100% sure about that.

Hope this helps,
Dan
 
Both ways gave me:


Microsoft JScript runtime (0x800A138F)
Object expected
 
Lambro, I had this EXACT same problem last week. The only problem with using JScript as your ASP language is the non-existance of a "Nothing" variable. In VBScript, you'd simply pull the session variable, check (result = Nothing) and go from there. Since JScript has no inherent value for Nothing (null does not work, I've tried) you have to code a workaround..... I found this on a website, and I can't remember where, but I thought it was rather brilliant. Create a VBScript function to return the Nothing value:
Code:
<script language="VBScript" runat="server">
Function nothingFunction
  Set nothingFunction = Nothing
End Function
</script>
Next, from your JScript, call the VBScript function to assign the Nothing value to a variable:
Code:
var nothing = nothingFunction(); // calls the VBScript function
Then after you pull the session variable, check to see if the two are equal. Put it all together and it'd look something like this:
Code:
<%@language="javascript"%>
<script language="VBScript" runat="server">
Function nothingFunction
  Set nothingFunction = Nothing
End Function
</script>

<%
var nothing = nothingFunction();
var blah = session("userinfo");
if (blah == nothing) {
   Response.Redirect("[URL unfurl="true"]http://www.advancedcontrolsolutions.com/sessionexpired.asp");[/URL]
}



-kaht

banghead.gif
 
As a side note, you can use the javascript defined nothing variable to destroy recordset objects like VBScript does. Javascript cleans them up itself via the garbage collection routine.

-kaht

banghead.gif
 
if I'm using langauge JavaScript, how do I use this:


<%
Session("varname") = request("var")
%>
 
Code:
<%
Session("varname") = Request("var")[b].Item[/b]
%>

-kaht

banghead.gif
 
Yeah.... it seems to be pretty common as of late....

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top