views:

193

answers:

1

Hi

I have an article in which I use PHP code inside the text editor in Joomla, in the backend. I can see jQuery already called when the page loads, here is my code inside the Article edit textbox:

<?php
$username="XXX";
$password="XXX";
$database="XXX";

mysql_connect('localhost',$username,$password) or die(mysql_error());
mysql_select_db($database) or die("Unable to select database");
$result=mysql_query("SELECT * FROM birthdays ORDER BY name")
or die(mysql_error());

echo "<table width='100%' cellspacing='10' cellpadding='0' border='0'>";
echo "<tr valign='top'><th align='left'></th><th align='left'>Name</th><th align='left'>Email</th><th align='left'>Day</th><th align='left'>Month</th></tr><tr><td>&nbsp;</td></tr>";

while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo '<td valign="top"><a href="#" id="'.$row['id'].'" class="delete_birthday"><img src="administrator/components/com_media/images/remove.png" alt="Delete user" /></a><input type="hidden" name="id[]" value="'.$row['id'].'" /></td>';
    echo "<td valign='top' style='border-bottom:1px dotted #333333; padding:2px;'>";
    echo $row['name'];
    echo "</td>";
    echo "<td valign='top' style='border-bottom:1px dotted #333333; padding:2px;'>";
    echo $row['email'];
    echo "</td>";
    echo "<td align='center' valign='top' style='border-bottom:1px dotted #333333; padding:2px;'>";
    echo $row['birthday'];
    echo "</td>";
    echo "<td align='center' valign='top' style='border-bottom:1px dotted #333333; padding:2px;'>";
    echo $row['birthmonth'];
    echo "</td>";
    echo "</tr>";
}
echo "</table>";
?>

<script type="text/javascript">
$(document).ready(function() {
    alert("hello");
});
</script>

At the moment, nothing alerts (just alerting for testing if jQuery gets recognised, I am obviously going to put in click handlers), so I assume the $(document).ready() never gets triggered. I can see the code in the source, but it just never gets called.

Anybody have any advice? BTW. the SC jQuery plugin is installed already to prevent library conflicts.

+3  A: 

According to the SC jQuery page, it loads jQuery in "no conflict" mode. This means that the $ function won't be available, and you need to use jQuery instead:

jQuery(document).ready(function() {
    ...
});

More information on jQuery.noconflict.

interjay