Forum Moderators: open

Message Too Old, No Replies

Accessing JavaScript variables in the HTML body.

Trouble using a variable for the VALUE in a PARAM tag.

         

thunter

3:43 am on May 6, 2004 (gmt 0)

10+ Year Member



Hi there,
Any help would be appreciated--I'm trying to create a page that plays a different Quicktime movie, based on a parameter in the querystring. However, the VALUE in the PARAM object is not being assigned correctly. Any thoughts? Thanks ahead of time.
These are the troublesome lines, I think:
<PARAM name="SRC" VALUE='movieVar'>
<EMBED SRC='movieVar'...>

<HEAD>
<TITLE>Play Movie Page</TITLE>
<SCRIPT language="JavaScript">
<!--
//get the parameter passed with the page.
var movieName = location.search.substring(1).toString();
var pageText = "";
var movieVar = "";

//array of the quicktime movies
var movies = new Array(2);
movies[0] = "quicktimes/movie0.mov";
movies[1] = "quicktimes/movie1.mov";

switch(movieName) {
case 'firstMovie':
pageText = "This is movie 1.";
document.title = "First Movie!";
movieVar = movies[0];
break;
case 'secondMovie':
pageText = "This is the movie 2.";
document.title = "Second Movie!";
movieVar = movies[1];
break;
}
-->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT language="JavaScript">document.write(pageText);</SCRIPT>
<br>

<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="320" HEIGHT="256" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">
[b]<PARAM name="SRC" VALUE='movieVar'>[/b]
<PARAM name="AUTOPLAY" VALUE="true">
<PARAM name="CONTROLLER" VALUE="true">
<EMBED [b]SRC='movieVar'[/b] WIDTH="320" HEIGHT="256" AUTOPLAY="true" CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/quicktime/download/"></EMBED>
</object>

</BODY>

RonPK

7:26 am on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<PARAM name="SRC" VALUE='movieVar'>
<EMBED SRC='movieVar'...>

You can't simply call a Javascript variable inside your HTML; you'll need to have it written by Javascript. So, try this:

<PARAM name="SRC" VALUE='<script>document.write(movieVar)</script>'>
<EMBED SRC='<script>document.write(movieVar)</script>'...>

Welcome to WebmasterWorld, thunter.

snookie

8:33 am on May 6, 2004 (gmt 0)

10+ Year Member



can u actually get the script to right it like that? surely the param tag is still open? why not document.write the whole object and param code to the page?

snookie

Bernard Marx

9:04 am on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah. Ithink (just from looking) there's a quoting problem, and the script will be literally entered into the attribute.

Maybe yes, write the whole thing, or bits like this:

<script>

document.write('<PARAM name="SRC" VALUE="'+movieVar+'">')</script> 

RonPK

1:21 pm on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



snookie, Bernard, you're both right. thunter, sorry for the mess...

thunter

2:42 pm on May 6, 2004 (gmt 0)

10+ Year Member



Thanks for the help everyone! I haven't got it yet, my syntax must be off...I'll check all the quotes and try again.

thunter

4:00 pm on May 6, 2004 (gmt 0)

10+ Year Member



Got it--thanks again folks. snookie, your suggestion to "document.write the whole object and param code to the page" worked (for some reason, using document.write for all the individual pieces didn't work?). I appreciate all the help.