Link to home
Start Free TrialLog in
Avatar of PvBredow
PvBredow

asked on

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



Avatar of bubbledragon
bubbledragon

I only can do this......

<a href="#" onClick="location.href='http:\\myserver\logging.asp?username='&usern&'&filename=file2.htm'">
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...

Avatar of PvBredow

ASKER

Thanks for the suggestion, but that doesn't seem to work for me.       Not sure what the problem is.
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
ASKER CERTIFIED SOLUTION
Avatar of bubbledragon
bubbledragon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial