Jump to content

ASP Help


chefytim
 Share

Recommended Posts

I am trying to get a very simple ASP page working but apparently I don't know what I'm doing.Here is my code so far:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><%	Sub Initialize()		Dim oShell		Set oShell = Server.CreateObject("Scripting.Shell")		strUserName = oShell.ExpandEnvironmentStrings("%USERNAME%")		strUserDomain = oShell.ExpandEnvironmentStrings("%USERDOMAIN%")		UserName.innerHTML = strUserName		UserFullName.innerHTML = strUserDomain	End Sub%><body onload="Initialize()">	<span id = "UserName"></span>	<span id = "UserFullName"></span></body></html>

It is complaining at the Set oShell command.Any help would be greatly appreciated.Thanks,Tim

Link to comment
Share on other sites

You won't be able to use innerHTML in that context, but what exactly is the error message?
OK, I change and had planned on changing those to HTML textboxes.Not sure how to assign a vbscript variable to an HTML textbox but once I get past the current issue I'll reseach that.The error message is:
Line: 11Error: Object expected

Line 11 is the Dim statement.When I debug the program in VStudio I get the following"Microsoft JScript runtime error: Object expected.Am I using correct call on the body onload?It just seems that is a JavaScript function but I'm not sure if it works with VBScript or not.

Edited by chefytim
Link to comment
Share on other sites

I didn't notice it before, but you're trying to use Javascript to call a VBscript function in ASP. That's not how it works, the ASP code runs and finishes before any Javascript runs. By the time Javascript runs there's no more ASP code, only Javascript. The error on line 11 is actually for the body tag, not the ASP function. If you open the web page in a browser and view the source of the page you'll notice that it does not contain any HTML code, and that line 11 is the body tag with the onload statement. The reason it can't find the function is because the function is defined in ASP, not Javascript, and the two aren't connected. You probably want to do something like this instead:

<body><%Dim oShellSet oShell = Server.CreateObject("Scripting.Shell")%>	<span id = "UserName"><%=oShell.ExpandEnvironmentStrings("%USERNAME%")%></span>	<span id = "UserFullName"><%=oShell.ExpandEnvironmentStrings("%USERDOMAIN%")%></span></body>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...