accessing javascript variables in HTML

K

ksr

Hello,

I have a HTML page, which loads an activeX control in the browser.
In the <HEAD> section, I have javascript similar to the following,

<SCRIPT language="JavaScript">
var Index = "";
// do some processing which sets a value to variable Index
</SCRIPT>

In the <BODY> section, I am downloading the cab file, which is an
activeX control, so the code is,

<BODY TEXT="#000000" BGCOLOR="#FFFFFF"..........>
<OBJECT ID="objID" CLASSID=...."CODEBASE="..>
<param name="name" value=..>.

</OBJECT>
</BODY>
</HTML>

In the param name=value pair, I want to assign the variable Index to
value. Just by doing value=Page, it does not work. Could someone
suggest how I can access javascript variable here?

Thankyou.
 
L

Laurent Bugnion

Hi,
Hello,

I have a HTML page, which loads an activeX control in the browser.
In the <HEAD> section, I have javascript similar to the following,

<SCRIPT language="JavaScript">
var Index = "";
// do some processing which sets a value to variable Index
</SCRIPT>

In the <BODY> section, I am downloading the cab file, which is an
activeX control, so the code is,

<BODY TEXT="#000000" BGCOLOR="#FFFFFF"..........>
<OBJECT ID="objID" CLASSID=...."CODEBASE="..>
<param name="name" value=..>.

</OBJECT>
</BODY>
</HTML>

In the param name=value pair, I want to assign the variable Index to
value. Just by doing value=Page, it does not work. Could someone
suggest how I can access javascript variable here?

Thankyou.

HTML is a static language, so it cannot access JavaScript variables. It
has to go the other way round, with JavaScript setting the HTML value.
Thankfully, with DOM Level 2 it has become much easier to do this kind
of things.

My suggestion is to set an ID on your PARAM node, and then use
document.getElementById to get it.

<param name="name" id="name" value="...">

Note that the ID must be unique throughout the whole HTML document.

Then:

var nParam = document.getElementById( "name" );
if ( nParam != null )
{
nParam.setAttribute( "value", Index );
}


HTH,
Laurent
 
K

ksr

Thanks for your reply.
I am new to DOM.
Can you post an example (syntax), for html page similar to that I
posted?
Thankyou.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top