0

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.

2 Answers 2

1

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>'
Sign up to request clarification or add additional context in comments.

Comments

1
document.getElementById('topartistdiv').innerHTML += '<a href="javascript:getAlbums(\'Beyonce\');">Albums</a>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.