Results 1 to 2 of 2

Thread: access a value of javascript function variable in html

  1. #1
    Join Date
    Jun 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default access a value of javascript function variable in html

    Hello
    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];
    }

    }
    </script>
    {/literal}
    <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>

  2. #2
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    First, you missed your closing quote and used the wrong symbol ( $ ) to separate GET variables:
    Code:
    <a href="{$JAMROOM_URL}/index.php?mode=cp$vault_id=xxx>
    To get JavaScript to do this, write the HTML like this:
    Code:
    <a href="{$JAMROOM_URL}/index.php?mode=cp&vault_id=" id="some_id">
    and add this line where you want to change the link:
    document.getElementById('some_id').href+=vault_idd;
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •