Hi,

I'm getting:

Parse error: parse error in C:\wamp\www\Ajax\getcd.php on line 28.

(I have highlighted line 28 in red.)

for the following simple program that retrieves data from cd_catalog.xml file and displays in txthint div when user selects artist's name from select box.

does anyone know on what i'm doing wrong? thank you.

getcd.html

<script language="javascript" type="text/javascript">
function showCD(str){
    if (str=="")
        {
            document.getElementById("txtHint").innerHTML="";
            return;
        }
    if (window.XMLHttpRequest)
        xmlhttp=new XMLHttpRequest();
    else
        xmlhttp=new activeXObject("Microsoft.XMLHTTP");

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText
    }

    xmlhttp.open("GET","getcd.php?q="+str,true);
    xmlhttp.send();
}
</script>

</head>

<body>
<form action="">
<select name="cds" onchange="showCD(this.value)">
<option value="">Select a CD</option>
<option value="Bob Dylan">Bob Dylan</option>
<option value="Bonnie Tyler">Bonnie Tyler</option>
<option value="Dolly Parton">Dolly Parton</option>
</select>
</form>
<div id="txtHint"><b>CD info will be listed here</b></div>
</body>
</html>

getcd.php

<?php
$q=$_GET['q'];

$xmlDoc=new DOMDocument();
$xmlDoc->load("cd_catalog.xml");

$x=$xmlDoc->getElementsByTagName('ARTIST');

for($i=0;$i<=$x->length-1;$i++)
    {
        //process only element nodes
        if ($x->item($i)->nodeType==1)
            {
                if ($x->item($i)->childNodes->item(0)->nodeValue==$q)
                    {
                        $y=($x->item($i)->parentNode);
                    }
            }
    }

$cd=($y->childNodes);

for($i=0;$i<$cd->length;$i++)
    {
        //process only element nodes
        if ($cd->item($i)->nodeType==1)
        {
            [COLOR="Red"]echo ("<b>".$cd->item($i)->nodeName.":</b>");[/COLOR]            echo ($cd->item($i)->childNodes->item(0)->nodeValue);
            echo ("<br/>");
        }
    }
?>

Try like this :

echo "<b>".$cd->item($i)->nodeName.":</b>";

or

$val=$cd->item($i)->nodeName;
echo "<b>".$val.":</b>";

commented: yes +5

Yes, you are right. It works fine now after removing the parentheses. thank you.

Always Post your code with code tags.
Mark this thread as solved if your problem solved.

commented: Good ! +11

Always Post your code with code tags.
Mark this thread as solved if your problem solved.

how to mark this thread as solved?

Just below this post under the heading "Has this thread been answered?" click "Mark this Thread as Solved" link

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.