Jens Bergvall
Jens Bergvall

Reputation: 1627

How to assign html title from variable with vbscript?

I'm currently trying to get a modal window to set my html <title> from a vbscript function like this:

<title> <%foo.bar%> </title>

where foo.bar

Function bar() as string

    bar = "some text"

end function

This gives no success.

I also tried the below snippets, but without success. It throws "An unhandled exception" for incompatible types.

<%@Language=VBScript%>

<% barVar = "fooFoo" %>

<title><%barVar%></title>

Does anyone know what possibly could be the problem here? Thanks for reading.

Upvotes: 0

Views: 1626

Answers (1)

user69820
user69820

Reputation:

You need to output the value using Response.Write():

<%@Language=VBScript%>

<% barVar = "fooFoo" %>

<title><% Response.Write barVar %></title>

or use the shortcut:

<%@Language=VBScript%>

<% barVar = "fooFoo" %>

<title><% = barVar%></title>

also, I've just noticed that your function definition includes a type, but VBScript does not include explicit typing and everything is a variant. So your function would be

function Bar()
    Bar = "some text"
end function

Upvotes: 3

Related Questions