Trailblazer Posted September 9, 2008 Share Posted September 9, 2008 Hi, I have a problem with my PHP response text. I am just programming some basic things to learn how AJAX works, what can and can't be done etc and have come to a halt at this one. My javascript calls a PHP page when a button is clicked, this PHP gets some information from the MySQL table and then creates the <a> with "onclick" functions inside which contain some custom JS functions that are defined on the original page. The function is as follows: area(number, number2, extraInfo). The first two instances that use area() do not need to use the extraInfo variable as this is so the PHP will know which entry to edit when that PHP is called from another JS function. But the extraInfo is needed for the <a> elements produced by the PHP and then sent to the HTML/JS page to be displayed. The HTML displays properly and when I view the page's source, everything is correct, but the <a> elements do not work, not even to call a JS alert(). When I take the extraInfo variable out of the area() function, the <a> elements work correctly just returning an alert() but when I put the extraInfo info in via the PHP variable $projectName, the <a> elements don't function anymore. Can anyone help? Or explain why this is happening? Sorry if this is hard to understand, I'll do my best to answer your questions if you are confused. Thanks, Trailblazer. P.S. The PHP response text (The area(2,1,$projectName); part): while(list($id,$projectName,$desc,$userName,$date,$startTime,$endTime) = mysql_fetch_row($result)) { $response .= "<tr><td>$id</td><td>$projectName</td><td>$desc</td><td>$userName</td><td>$date</td><td>$startTime</td><td>$endTime</td><td><a><div onmouseup='area(2,1,$projectName);'>Edit</div></a></td><td><a href='accountp.php?op=4&id=$id'>Delete</a></td></tr>"; } The JS function area(): function area(number,number2,extraInfo) { alert("test"); if(number == 1) { document.getElementById('contentarea').innerHTML = "<div id='content'><h1>Account</h1><br /><br /><h2>Last Viewed Project</h2><br /><br /><h2>User Info</h2></div>"; } else if(number == 2) { if(number2 == 0) { showProjects(); } else if(number2 == 1) { alert("test2"); editProject(extraInfo); } } else if(number == 3) { document.getElementById('contentarea').innerHTML = "<div id='content'><h1>Preferences</h1><br /><br /><h2>Account Settings</h2><br /><br /><h2>Extra Settings</h2></div>"; } } As I said, the resulting HTML/JS is output correctly when looking at the source of the page, but the <a> elements do not work. I have also tried using <input type="button"> elements as well as <div> elements to no avail. Quote Link to comment Share on other sites More sharing options...
libertyct Posted September 12, 2008 Share Posted September 12, 2008 yup im having the same problem. it seems javascript wont work in divs populated with data from my ajax resquests ??? im using prototype btw Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.