I have a [B]contact[b]contact ID
At the bottom of this table I have a button that calls a new JS function that should replace the current table with a table specifically about the selected [b]contact
However when the “onclick” event happens, noting happens, at all. No javascript errors, no PHP errors, no return, nada. Could it be due to the fact that these radio buttons aren’t included in the source code, so the external js function can’t access them? I have no idea, because the buttons included on the page work as much as you wan’t (changing between personal or group contacts).
Heres the script:
[code=php]
////////////
//My Table
$display = “<div class=’tbl_bg’>”;
$display .= “<table><thead><tr>”;
$display .= “<th class=’main’ colspan=’4′>$title</th></tr><tr>”;
$display .= “<th>Name</th>”;
$display .= “<th>Email</th>”;
$display .= “<th>Work Phone</th>”;
$display .= “<th>View Details</th></tr></thead>”;
$i = 0;
while(list($id, $name,$email,$w_phone) = mysql_fetch_array($result))
{
$tr = ($i%2 == 0) ? “<tr style=’background-color:#E0EEEE’>” : “<tr style=’background-color:#FFE4C4′>”;
if (($email == “”) || (!$email)) {
$email = “ ”;
}
if (($w_phone == “”) || (!$w_phone)) {
$w_phone = “ ”;
}
if ((!$name) || ($name == “”)) {
continue;
}
$display .= “$tr<td>$name</a></td>”;
$display .= “<td>$email</td>”;
$display .= “<td>$w_phone</td>”;
$display .= “<td align=’center’><input type=’radio’ name=’selectedContact’ value=’$id’></td></tr>”;
$i++;
}
$display .= “<tr><td colspan=’3′> </td><td align=’center’>”;
$display .= “<input type=’button’ value=’Show Details’ name=’showMe’ onclick=”showDetails()”></td></tr>”;
//^^Button
$display .= “</table></form></div>”;
[code=php]
//My Function
///////////////
function showDetails(button)
{
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try{
ajaxRequest = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e){
// Not supported
alert(“AJAX supported browser required for this page.”);
return false;
}
}
}
ajaxRequest.onreadystatechange = function()
{
if (ajaxRequest.readyState == 4)
{
var ajaxDisplay1 = document.getElementById(‘dispContacts1’);
var ajaxDisplay2 = document.getElementById(‘dispContacts2’);
var ajaxDisplay3 = document.getElementById(‘dispDetails’);
ajaxDisplay1.innerHTML = “”;
ajaxDisplay2.innerHTML = “”;
if ((ajaxRequest.responseText == “”) || (ajaxRequest.responseText == null))
{
ajaxDisplay3.innerHTML = “NO RESPONSE TEXT”;
}
else
{
ajaxDisplay3.innerHTML = ajaxRequest.responseText;
}
}
var radField = document.detailform.selectedContact;
var radLength = document.detailForm.selectedContact.length;
for (var i=0; i<radLength; i++) {
if (radField[i].checked) {
var chkContact = radField[i].value;
continue;
}
}
var detailQuery = “?id=” +chkContact;
ajaxRequest.open(“GET”, “contactDetails.php” +detailQuery, true);
ajaxRequest.send(null);
}
}
[code=php]
//The script to get details
////////////////////////////
if (isset($_GET[‘id’])) {
$id = $_GET[‘id’];
}
else {
echo “No Get Qeury!”;
}
$query = “SELECT * FROM contacts WHERE id=’$id'”;
$result = mysql_query($query,$db) or die (mysql_error());
$row=mysql_fetch_Array($result);
$display = “<div class=’tbl_bg’><table class=’form’><tr><th colspan=’2′>Contact Details</th></tr>”;
$display .=”<tr><td align=’right>Name: </td><td>”.$row[‘name’].”</td></tr>”;
$display .=”<tr><td align=’right>Primary Email: </td><td>”.$row[’email’].”</td></tr>”;
$display .=”<tr><td align=’right>Other Email: </td><td>”.$row[‘alt_email’].”</td></tr>”;
$display .=”<tr><td align=’right>Work Phone: </td><td>”.$row[‘w_phone’].”</td></tr>”;
$display .=”<tr><td align=’right>Cell Phone: </td><td>”.$row[‘c_phone’].”</td></tr>”;
$display .=”<tr><td align=’right>Other Phone: </td><td>”.$row[‘o_phone’].”</td></tr>”;
$display .=”<tr><td align=’right>Address: </td><td><textarea readonly=’readonly’>”.$row[‘address’].”</textarea></td></tr>”;
$display .=”<tr><td align=’right>Comments: </td><td><textaera readonly=’readonly’>”.$row[‘comments’].”</textarea></td></tr>”;
$display .=”</table></div>”;
echo mysql_error();
echo $id.”<br>”;
echo $query.”<br>”;
echo $display;
Pretty hard to tell whats wrong when nothing produces an error and nothing happens.