Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Passing array variable-should be simple for an expert

    I have inherited some code, and cannot get it to work. Note the bold section in the OBJECT tag below. I believe this is where the issue is.

    Code:
    <script language="JavaScript">
    var camArray = new Array();
    camArray['Dolliver'] = "http://video.dot.ca.gov/asx/D5-Bello-at-101.asx";
    camArray['Mattie'] = "http://video.dot.ca.gov/asx/D5-Mattie-Rd-at-101.asx";
    camera="Dolliver";
    
    var camHTMLd = "<object id='MediaPlayer' width=320 height=240 classid='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' standby='Loading Windows Media Player components...' type='application/x-oleobject' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'><param name='filename' value='"+camArray[camera]+"'><param name='Showcontrols' value='False'><param name='autoStart' value='True'><embed type='application/x-mplayer2' src='"+camArray[camera]+"' width=320 height=240></embed></object>"
    
    function changeCam(camera){
    
    	document.getElementById("caltransCamera").innerHTML = camHTMLd;
    	//alert(camHTMLd+camArray[camera]);
    }
    
    </script>

    Then in the page, I have the following code:
    <a href="javascript:changeCam('Mattie');">101 at Mattie Road</a>

    It SHOULD open and start displaying the MATTIE cam, but it reloads the default Dolliver.

    What am I missing? Thank you in advance.

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    In your code, the HTML string is only set once - you need to set it every time the function is called:

    Code:
    <script type="text/javascript">
    var camArray = new Array();
    camArray['Dolliver'] = "http://video.dot.ca.gov/asx/D5-Bello-at-101.asx";
    camArray['Mattie'] = "http://video.dot.ca.gov/asx/D5-Mattie-Rd-at-101.asx";
    camera="Dolliver";
    
    var camHTMLd = "<object id='MediaPlayer' width=320 height=240 classid='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' standby='Loading Windows Media Player components...' type='application/x-oleobject' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'><param name='filename' value='"+camArray[camera]+"'><param name='Showcontrols' value='False'><param name='autoStart' value='True'><embed type='application/x-mplayer2' src='"+camArray[camera]+"' width=320 height=240></embed></object>"
    
    function changeCam(camera){
        camHTMLd = "<object id='MediaPlayer' width=320 height=240 classid='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' standby='Loading Windows Media Player components...' type='application/x-oleobject' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'><param name='filename' value='"+camArray[camera]+"'><param name='Showcontrols' value='False'><param name='autoStart' value='True'><embed type='application/x-mplayer2' src='"+camArray[camera]+"' width=320 height=240></embed></object>";
        document.getElementById("caltransCamera").innerHTML = camHTMLd;
        //alert(camHTMLd+camArray[camera]);
    }
    
    </script>

  • Users who have thanked gusblake for this post:

    jmwebguy (01-13-2010)

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Perfect. Thank you so much!


  •  

    Tags for this Thread

    Posting Permissions

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