View Full Version : access a value of javascript function variable in html

07-10-2008, 07:10 PM
I am trying to access a value of javascript function variable in html
but I do not know how, can somebody help me.
There is a function called getItemData in which I get the values and I want to use one of these values (vault_id) as a part of my href code in html (<a href="/index.php?mode=cp$vault_id=xxx>buy it now</a>)
The code looks like this :

<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var currentItem;
var vault_idd="hello";

function getUpdate(typ,pr1,pr2,swf) {
if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }

function getItemData(idx) {
var obj = thisMovie("jstest").itemData(idx);
document.getElementById("title").innerHTML = obj["title"];
document.getElementById("album").innerHTML = obj["album"];
document.getElementById("artist_info").href = obj["artist_info"];
document.getElementById("artist_info").innerHTML = obj["artist_info"];
document.getElementById("price").innerHTML = obj["price"];
document.getElementById("genre").innerHTML = obj["genre"];
document.getElementById("artist").innerHTML = obj["artist"];
document.getElementById("vault_id").value = obj["vault_id"];
/* vault_idd=document.getElementById("vault_id").value ;*/
document.vault_idd = "test" ;

function thisMovie(movieName) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];

<font color="white">
Song Name: <div id="title"><font color="#FF6633"></font></div>
Song Genre: <div id="genre"><font color="#FF6633">the genre shows here</font></div>
Song Album: <div id="album"><font color="#FF6633">the album shows here</font></div>
Artist: <div id="artist"><font color="#FF6633">the artist shows here</font></div>
Artist Info: <a id="artist_info" ><div id="artist_info"><font color="#FF6633">the artist info shows here</font></a></div>
Song Price: <div id="price"><font color="#FF6633">the price here</font></div>

Buy it now: <a href="{$JAMROOM_URL}/index.php?mode=cp$vault_id=xxx><img src="{$SKIN_URL}/images/add_cart.gif"></a>

07-13-2008, 01:00 PM
First, you missed your closing quote and used the wrong symbol ( $ ) to separate GET variables:
<a href="{$JAMROOM_URL}/index.php?mode=cp$vault_id=xxx>

To get JavaScript to do this, write the HTML like this:
<a href="{$JAMROOM_URL}/index.php?mode=cp&vault_id=" id="some_id">and add this line where you want to change the link:

P.S. A form submission would be a better way to do this because the user can click on the incomplete link as it is.