How to use a vbscript variable in html?

I have a html page containing some client-side Vbscript.        The script reads the registry, determines the Windows logon name, and stores this in a variable.

On my page, I have many href's, that call to an ASP page, passing parameters I use for logging in the querystring.
My problem is that I can't figure out the syntax needed to use the value stored in the script variable in the html.

for example:

<script type="text/vbscript">
usern=getusername {assume this is where the logon name is read from the registry}
</script>

<a href="http:\\myserver\logging.asp?username= usern&filename=file1.htm">link 1</a>
<a href="http:\\myserver\logging.asp?username= usern&filename=file2.htm">link 2</a>
<a href="http:\\myserver\logging.asp?username= usern&filename=file3.htm">link 3</a>
<a href="http:\\myserver\logging.asp?username= usern&filename=file4.htm">link 4</a>

etc.

I don't want to end up with:
<a href="http:\\myserver\logging.asp?username= " & <script type="text/vbscript">getusername</script>& "filename=file1.htm">link 1</a>

repeated many times, once for each href.

I have seen the syntax <%=myvar%> used in HTML, but if I understand correctly, that only works in ASP, not in client side scripting.

I strongly suspect that defining a variable value in a script and then referencing that value in HTML should be a very common issue, but I haven't been able to find an example that shows how to do that, client-side using Vbscript.

Please help!

         thanks very much.
                          Pvbredow



PvBredowAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
bubbledragonConnect With a Mentor Commented:
Try this.. Only work on IE.
Not standard script becuase document.writeln will cause the page rewrite. But can run on my browse. so strange.....

<html>
<head></head>
<body>
<script type="text/vbscript">
      myurl="http://www.google.com"
      mydesc="Google search"
</script>

<a href="javascript:location.href=myurl"><script>document.writeln(mydesc)</script></a><BR>

</body>
</html>
0
 
bubbledragonCommented:
I only can do this......

<a href="#" onClick="location.href='http:\\myserver\logging.asp?username='&usern&'&filename=file2.htm'">
0
 
bubbledragonCommented:
You must use <script></script> to declare this is script section, like <%%> on ASP.

If you write on HTML, the browse will view as TEXT only.

onClick event will trigger the statement same as put its inside a <script> tags.

So, put the script statement inside the onClick event to declare this is a script and you can use the usern variable.

I think this is a simple way if you want to skip the script tags.

Hope I can explain clearly.... for my English...

0
 
PvBredowAuthor Commented:
Thanks for the suggestion, but that doesn't seem to work for me.       Not sure what the problem is.
0
 
PvBredowAuthor Commented:
I'm not sure I understand your suggestion properly.       To try to get a simple example working, I tried this:

<html>
<header>
</header>

<body>

<script type="text/vbscript">
dim myurl
myurl="http://www.google.com"
dim mydesc
mydesc="Google search"
</script>

<a href="#" onClick="location.href='&<script type="text/vbscript">myurl</script>&'"><script type="text/
vbscript">mydesc</script></a>

</body>
</html>

I am simply trying to define two variables within the script, for the URL & description of a link, and then reference them within my href.       This doesn't work.       Can you help me to identify what is wrong with this example?

thanks very much
0
All Courses

From novice to tech pro — start learning today.