By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

accessing javascript variables in HTML

P: n/a
ksr
Hello,

I have a HTML page, which loads an activeX control in the browser.
In the <HEADsection, 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 <BODYsection, 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.

Aug 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

ksr wrote:
Hello,

I have a HTML page, which loads an activeX control in the browser.
In the <HEADsection, 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 <BODYsection, 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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 26 '06 #2

P: n/a
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.

Laurent Bugnion wrote:
Hi,

ksr wrote:
Hello,

I have a HTML page, which loads an activeX control in the browser.
In the <HEADsection, 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 <BODYsection, 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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.