Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referring to javascript variables 1

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
AU
Hi,

If I've declared some variables in javascript:

ffile='10x7';
fwid=797
fhei=45

How do I refer to it in the html to form as part of tage for a flash document, for example:

<OBJECT classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot; WIDTH=##javascript var fwid here## HEIGHT=##javascript var fhei here##>

Thanks..
 
<script language=&quot;javascript&quot; type=&quot;text/javascript&quot;>
<!--
// place this in the <body> where u want the OBJECT to be
var ffile='10x7'; // what this for ?
var fwid=797;
var fhei=45;
document.write('<OBJECT classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot; WIDTH=' + fwid + 'HEIGHT=' + fhei + '>');
//-->
</script>
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
you should be able to give your object tag a name attribute, then reference it by that name, similar to:

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title></title>
<meta name=&quot;Author&quot; content=&quot;&quot;>
<meta name=&quot;Keywords&quot; content=&quot;&quot;>
<meta name=&quot;Description&quot; content=&quot;&quot;>

<script language=&quot;javascript&quot;>
function init() {
	iWidth = 100;
	iHeight = 100;
	oFlash.style.width = iWidth + &quot;px&quot;;
	oFlash.style.height = iHeight + &quot;px&quot;;
}
</script>

<style type=&quot;text/css&quot;>
</style>
</head>

<body onLoad=&quot;init();&quot;>
<OBJECT classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;
	codebase=&quot;[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0&quot;;[/URL]
	style=&quot;border:1px solid black;&quot;
	name=&quot;oFlash&quot;>

</body>
</html>
 
hi there,

there is only one way that I know of.

try building the entire tag using a document.write()
that way you can concatenate the variables into the string.
for example:

Code:
var ffile='10x7';
var fwid=797;
var fhei=45;
Put the following in the body of your html file
Code:
<script language=&quot;JavaScript&quot;>
document.write(&quot;<OBJECT classid=\&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\&quot; codebase=\&quot;[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\&quot;[/URL] WIDTH=&quot; & fwid & &quot;HEIGHT=&quot; & fhei &&quot;>&quot;);
</script>
 
jemminger,

I've tried your code and it works well, but what is the rest of it for filename and embed filename,width&height?

Here's what I've got so far,with the blanks:

<OBJECT classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;
codebase=&quot; name=&quot;oFlash&quot;>
<PARAM NAME=movie VALUE=&quot;##javascript var ffile##.swf&quot;> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src=&quot;##javascript var ffile##.swf&quot; menu=false quality=high bgcolor=#FFFFFF WIDTH=##javascript var fwid## HEIGHT=##javascript var fhei## TYPE=&quot;application/x-shockwave-flash&quot; PLUGINSPAGE=&quot;</OBJECT>

Thanks in advance.
 
Hi DeepBlerg,

If you want to dynamically declare the file to open, you'll have to use the method NEVERSLEEP shows above:

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title></title>
<meta name=&quot;Author&quot; content=&quot;&quot;>
<meta name=&quot;Keywords&quot; content=&quot;&quot;>
<meta name=&quot;Description&quot; content=&quot;&quot;>

<script language=&quot;javascript&quot;>
function writeFlash() {
    sFile = &quot;10x7.swf&quot;;
    iWidth = 100;
    iHeight = 100;

	document.writeln('<OBJECT classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot;[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0&quot;>');[/URL]
	document.writeln('<EMBED src=&quot;' + sFile + '&quot; menu=false quality=high bgcolor=#FFFFFF width=&quot;' + iWidth + 'px&quot; height=&quot;' + iHeight + 'px&quot; TYPE=&quot;application/x-shockwave-flash&quot; PLUGINSPAGE=&quot;[URL unfurl="true"]http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash&quot;></EMBED>');[/URL]
	document.writeln('<PARAM NAME=movie VALUE=&quot;' + sFile + '&quot;><PARAM NAME=menu VALUE=false><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF></OBJECT>');
}
</script>

<style type=&quot;text/css&quot;>
</style>
</head>

<body>
<script language=&quot;javascript&quot;>writeFlash();</script>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top