Reputation: 117
I'm having another difficulty with my website project. Ok here is my problem...
<script>
function getTopArtist(){
if (window.XMLHttpRequest){
topartist = new XMLHttpRequest();
}
else{
topartist = new ActiveXObject("Microsoft.XMLHTTP");
}
topartist.onreadystatechange=function(){
try{
if (topartist.readyState==4 && topartist.status==200){
var ArtistDetails = topartist.responseXML.documentElement.getElementsByTagName("artist");
for(i=0;i<=2;i++){
myartistname = ArtistDetails[i].getElementsByTagName('name')[0].firstChild.nodeValue;
alert(myartistname)
document.getElementById('topartistdiv').innerHTML+='<a href="javascript:getAlbums(this is the proble here);">Albums</a>';
}
}
catch(er){
alert("Oops something went wrong!");
}
}
topartist.open("GET","http://localhost/test/topartist.php",true);
topartist.send(null);
}
</script>
My problem is on line 17 when I'm trying to put the artist name inside the brackets to then I can send them to another function. So let's say it alerts Beyonce
I want the link to be like this.
javascript:getAlbums('Beyonce');
I guess it has something to do with special characters but I can't figure it out. Any help will be appreciated.
Upvotes: 0
Views: 266
Reputation: 27441
document.getElementById('topartistdiv').innerHTML += '<a href="javascript:getAlbums(\'Beyonce\');">Albums</a>';
Upvotes: 1
Reputation: 490273
You need to quote the string, and you have already used '
for the JavaScript string and "
for the HTML attribute string.
Use escaped single quote, \'
.
'<a href="javascript:getAlbums(\'no problemo\');">Albums</a>'
Upvotes: 1