| Author |
How to assign dynamic value to <param > tage
|
Matt Brown
Ranch Hand
Joined: Jan 26, 2004
Posts: 69
|
|
I need to pass a dynamic value to a object in a HTML, which is something like:
<html lang="en">
<head>
...
<SCRIPT language='JavaScript' charset='utf-8'> <!--
function setInit{
...
var init = 12345;
...
}
// --> </SCRIPT>
</head>
...
<object id="myObj" type="...." ....>
<param name='myVars' value='initVar="+init+"'; />
</object>
...
</html>
The init value 12345 was not passed, in stead " init " was passed. What did I do wrong?
|
"I just use my muscles as a conversation piece, like someone walking a cheetah down 42nd Street." - Arnold Schwarzenegger
|
 |
Vallidevi Appana
Greenhorn
Joined: Jun 30, 2006
Posts: 25
|
|
Hi Matt,
You can use body onload attribute to load the value.
You can refer the following piece of code.
<html>
<head>
<script>
var paramValue = 1234;
function setTextBoxValue(){
document.getElementById("textBox1").value=paramValue;
}
</script>
</head>
<body onload="setTextBoxValue()">
<input type="text" id="textBox1"/>
</body>
</html>
Regards
Valli
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
You really should be doing it with a serverside language if it requires no input from the user or the browser.
you probably want to use DOM methods or document.write.
Eric
|
 |
Matt Brown
Ranch Hand
Joined: Jan 26, 2004
Posts: 69
|
|
The original data is Form input and a Javascript is called with a onclick event to process the input. The init variable is a result of processing.
Eric, Could you help me with this?
|
 |
Matt Brown
Ranch Hand
Joined: Jan 26, 2004
Posts: 69
|
|
Bear, Valli:
I tried the code below:
<!-- saved from url=(0014)about:internet -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Portfolio</title>
<SCRIPT language='JavaScript' charset='utf-8'> <!--
function callInit() {
var paramElement = document.createElement("param");
paramElement.setAttribute("id", "flash");
paramElement.setAttribute("name", "flashVars");
paramElement.setAttribute("value", "quoteShare=JAVA:3322"); //hard coded value for testing
var objElement = document.getElementById("myPortfolio");
objElement.appendChild(paramElement);
var children = objElement.childNodes;
for (k=0; k<children.length; k++) {
alert(k+"=> id:"+children[k].id+"; name:"+children[k].name+"; value:"+children[k].value+"; tagName:"+children[k].tagName);
}
//I did see the <param id='flash' ...> was added under <object>. The loop shows 6 children. Three of them are "undefined". I'm not sure where are they from
objElement.loadQuotes();
}
// --> </SCRIPT>
</head>
<body scroll="yes">
<table>
<tr>
<td>
<div style="width:192px;height:310px;border:1px solid rgb(0, 0, 0);">
<table border="0">
<tr>
<td >
You may enter your own symbol and shares with correct format (e.g., IBM:100)
</td>
</tr>
<tr>
<td >
<textarea id="quoteShare" style="width:186px;font-weight:bold;font-size:11px;" rows="13" >
YHOO:200
JAVA:123
</textarea>
</td>
</tr>
<tr>
<td>
<button onclick="callInit()" type="button" style="color:#242F6D;font-weight:bold;font-size:10px;">Get Values of My Portfolio</button>
</td>
</tr>
</table>
</div>
<td>
<td>
<table border="0" >
<tr >
<td >
<object id="myPortfolio" type="application/x-shockwave-flash" data="MyPortfolio.swf" WIDTH="850" HEIGHT="460" >
<param id='param1' name='movie' value='MyPortfolio.swf'/>
<embed id='embed1' name='myPortfolio' src='MyPortfolio.swf' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' height='460' width='850'/>
</object>
</td>
</tr>
</table>
<td>
</tr>
</table>
</body>
</html>
The variable "quoteShare" was not passed to the swf object.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
It probably did not change since it is not reading the value after you change it. Sounds like you need to use createElement or innerHTML and replace the object tag on the page when you have the info.
Eric
|
 |
Matt Brown
Ranch Hand
Joined: Jan 26, 2004
Posts: 69
|
|
I tried something like:
function callInit() {
var paramElement = document.createElement("param");
paramElement.setAttribute("id", "flash");
paramElement.setAttribute("name", "flashVars");
paramElement.setAttribute("value", "quoteShare=JAVA:3322");;
var objElement = document.getElementById("myPortfolio");
objElement.appendChild(paramElement);
var myElement = document.getElementById("flash");
alert(myElement.value); //It shows the value correctly
}
...
<object id="myPortfolio" type="application/x-shockwave-flash" data="MyPortfolio.swf" WIDTH="850" HEIGHT="460" >
<param name='movie' value='MyPortfolio.swf'/>
<embed name='myPortfolio' src='MyPortfolio.swf' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' height='460' width='850'/>
</object>
The swf object was called, but the param "flashVars" was not passed with the call.
If I just add the element <param name='flashVars' value='quoteShare=JAVA:123' /> within <object>, the 'flashVars' variable will be passed.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.
You can go back and change your post to add code tags by clicking the button on your post.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Matt Brown
Ranch Hand
Joined: Jan 26, 2004
Posts: 69
|
|
I did some more testing on the <object > of swf and <param> for the flashVars. It seems that the swf <object> loaded the <param > elements
within it and kept using the initial <param > even though the <param> elements are updated or new <param > elements are added later.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Create the entire object, not just the parameter.
Eric
|
 |
Matt Brown
Ranch Hand
Joined: Jan 26, 2004
Posts: 69
|
|
|
Is there a way to reload the <object > with an event?
|
 |
 |
|
|
subject: How to assign dynamic value to <param > tage
|
|
|