...

View Full Version : (**SOLVED**) why do i keep getting errors



skatermike21988
12-28-2006, 09:19 AM
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:


<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


<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

_Aerospace_Eng_
12-28-2006, 09:28 AM
It looks fine. Try this

document.getElementById("playlist").innerHTML +=artist+' - '+title+'<input type="button" value="Play" onclick="'+java+'"><br>';

Try alerting j to see if its the right value.

skatermike21988
12-28-2006, 09:41 AM
yup it's the right value, and i tried that still errors, i don't seem to understand why i'm getting errors

_Aerospace_Eng_
12-28-2006, 10:56 AM
What errors are you getting? You haven't told us that yet you know? We aren't psychic.

skatermike21988
12-28-2006, 07:00 PM
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

_Aerospace_Eng_
12-28-2006, 08:42 PM
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.

skatermike21988
12-30-2006, 03:53 AM
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

skatermike21988
12-30-2006, 04:27 AM
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:




<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>

skatermike21988
12-30-2006, 06:23 AM
So anybody have any ideas why? This is starting to get very frustrating

skatermike21988
12-30-2006, 08:59 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum