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 10 of 10
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    (**SOLVED**) why do i keep getting errors

    ok i have a code that pulls data out from a xml file, once pulled i have the javascript parse it to the page, that all works, now i need it to have add a link to refer to another javascript function.

    The problem is this.

    My code works fine like this:
    Code:
    <script type="text/javascript">
    function changemusic(id) {
    
    xmlDoc=loadXMLDoc('changemusic.php?id='+id);
    var playlist_div=document.getElementById("playlist");
    playlist_div.innerHTML='';
    
    
    var x=xmlDoc.getElementsByTagName('artist');
    var k=xmlDoc.getElementsByTagName('title');
    var j=xmlDoc.getElementsByTagName('java');
    for (i=0;i<x.length;i++)
      {
    var artist=(x[i].childNodes[0].nodeValue)
    var title=(k[i].childNodes[0].nodeValue) 
    var java=(j[i].childNodes[0].nodeValue)
    
     
    document.getElementById("playlist").innerHTML +=artist+' - '+title+'<input type=button  value=play><br>';
     }
    
    }
    </script>
    Butonce i add the onclick command to the button i recieve errors
    Code:
    <script type="text/javascript">
    function changemusic(id) {
    
    xmlDoc=loadXMLDoc('changemusic.php?id='+id);
    var playlist_div=document.getElementById("playlist");
    playlist_div.innerHTML='';
    
    
    var x=xmlDoc.getElementsByTagName('artist');
    var k=xmlDoc.getElementsByTagName('title');
    var j=xmlDoc.getElementsByTagName('java');
    for (i=0;i<x.length;i++)
      {
    var artist=(x[i].childNodes[0].nodeValue)
    var title=(k[i].childNodes[0].nodeValue) 
    var java=(j[i].childNodes[0].nodeValue)
    
     
    document.getElementById("playlist").innerHTML +=artist+' - '+title+'<input type=button value=Play onclick='+java+'><br>';
     }
    
    }
    </script>
    Any ideas why?

    All help appreciated.

    Mike
    Last edited by skatermike21988; 12-30-2006 at 09:00 AM. Reason: mispellings

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    It looks fine. Try this
    Code:
    document.getElementById("playlist").innerHTML +=artist+' - '+title+'<input type="button" value="Play" onclick="'+java+'"><br>';
    Try alerting j to see if its the right value.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yup it's the right value, and i tried that still errors, i don't seem to understand why i'm getting errors
    Last edited by skatermike21988; 12-28-2006 at 09:58 AM.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What errors are you getting? You haven't told us that yet you know? We aren't psychic.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    What errors are you getting? You haven't told us that yet you know? We aren't psychic.
    I am getting an error stating object expected

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Any way you can post a link to your page? Object expected usually means something like the div you are trying to change the innerHTML to doesn't exist when you call the function. Try using Firefox. It will give you a better explanation of the error in the javascript console.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Any way you can post a link to your page? Object expected usually means something like the div you are trying to change the innerHTML to doesn't exist when you call the function. Try using Firefox. It will give you a better explanation of the error in the javascript console.
    The link is:
    http://www.music.friendshideout.com/desktopplayer.php

    You will need to register as it requires a user to be register'd. The link will come up in a new page, after you register you can exit and log in, you will see my picture as i will automaticly be a friend. Click on my picture and i list will show up, once play is clicked that is where i recieve the error

  • #8
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    By the way i tried it in firefox, the error console returns nothing, and it doesn't even work in firefox. i will post my whole javascript code that includes the function to play the song:


    Code:
    <script type="text/javascript" src="loadxmldoc.js"> 
    <script type="text/javascript">
    
    function song(what,who){
    document.getElementById("music1").innerHTML='<object id="mediaplayer1" width="200" height="45" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject"><param name="URL" value="'+what+'"><param name="AutoStart" VALUE="True"><param name="uiMode" value="full"><embed type="application/x-mplayer2" src="'+what+'" ShowControls="1" AutoStart="1" width="200" height="45"></embed></object>';
    nowplaying(who);
    return false;
    }
    
    function nowplaying(who)
    {
    document.getElementById("playing").innerHTML='<font color="blue"><h4>Now Playing '+who;
    		
    	
    }
    
    
    
    
    </script>
    
    <script type="text/javascript">
    function changemusic(id) {
    
    xmlDoc=loadXMLDoc('changemusic.php?id='+id);
    var playlist_div=document.getElementById("playlist");
    playlist_div.innerHTML='';
    
    
    var x=xmlDoc.getElementsByTagName('artist');
    var k=xmlDoc.getElementsByTagName('title');
    var j=xmlDoc.getElementsByTagName('java');
    var playlist = document.getElementById("playlist");
    for (i=0;i<x.length;i++)
      {
    var artist=(x[i].childNodes[0].nodeValue)
    var title=(k[i].childNodes[0].nodeValue) 
    var java=(j[i].childNodes[0].nodeValue)
    
    
    
    if(artist=='') {
    
    document.getElementById("playlist").innerHTML ='User Has No Songs Uploaded';
    
    }
    else
    {
     
    document.getElementById("playlist").innerHTML +=artist+' - '+title+'<input type="button" value="Play" onclick="'+java+'";><br>';
    
    }
    
     }
    
    }
    </script>

  • #9
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So anybody have any ideas why? This is starting to get very frustrating

  • #10
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    god i'm stupid problem is solved, i didn't close one of <script> tags!!! duh, all is working now, thanks for the help guys


  •  

    Posting Permissions

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