chefytim Posted July 8, 2011 Share Posted July 8, 2011 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 More sharing options...
justsomeguy Posted July 8, 2011 Share Posted July 8, 2011 You won't be able to use innerHTML in that context, but what exactly is the error message? Link to comment Share on other sites More sharing options...
chefytim Posted July 9, 2011 Author Share Posted July 9, 2011 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 11, 2011 Share Posted July 11, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.