Results 1 to 2 of 2

Thread: ajax problem, think something is wrong with my javascript

  1. #1
    Join Date
    May 2007
    Thanked 0 Times in 0 Posts

    Default ajax problem, think something is wrong with my javascript

    so i took this tutorial on ajax and tried to apply what i learned to do what i want it to do. it's not working. i think something's wrong with my javascript, particularly maybe with my onclick function, or the passing of the variables between js functions. i've posted my relevant code below, removing parts of the page that don't have anything to do with the ajax.

    the form name is editEmailContacts which is inside a hidden div, made visible by scriptaculous, and trying to run editEmailContacts() onclick.

    i am curious, this is a php page that starts off with $_GET to display variables below. does the ajax response need to have include these variables as well in order for the page to display correctly after the ajax communication?




    $recordID = $_GET['recordID'];
    $userName = $_GET['userName'];
    $userGroup = $_GET['userGroup'];
    $userEmail = $_GET['userEmail'];

    $record_query = "SELECT * FROM records WHERE record_id = '" . $recordID . "'";
    $record_result = mysql_query($record_query) or die(mysql_error());
    $record_row = mysql_fetch_array($record_result);

    $comment_query = "SELECT * FROM comments WHERE comment_record = '" . $recordID . "' ORDER BY comment_date DESC";
    $comment_result = mysql_query($comment_query) or die(mysql_error());
    $comment_numRows = mysql_num_rows($comment_result);


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Details For Record ID #<?php echo $recordID; ?></title>
    <link href="css/global.css" rel="stylesheet" type="text/css" />
    <link href="css/popup.css" rel="stylesheet" type="text/css" />
    <script src="js/scriptsBy10.js" type="text/javascript"></script>
    <script src="js/prototype.js" type="text/javascript"></script>
    <script src="js/scriptaculous.js" type="text/javascript"></script>
    <script type="text/javascript">
    var xmlHttp
    function editEmailContacts() {
    if (xmlHttp==null) {
    alert ("You are using an incompatible browser.")
    var type=document.getElementById('additionalEmailType').value
    var email=document.getElementById('additionalEmail').value
    var url="editEmail.php"
    url=url+"&recordID"+<?php echo $recordID; ?>
    function stateChanged(type) {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    if (type=="replace") {
    if (type=="include") {
    new Effect.BlindUp('editEmail');
    function GetXmlHttpObject() {
    var xmlHttp=null;
    xmlHttp=new XMLHttpRequest();
    return xmlHttp;


    <?php //removed irrelevant parts of the code here ?>

    <div id="editEmail" style="display:none" class="hiddenDIV">
    <div align="right" class="hiddenDIVheader">
    <p>Edit Email Contacts&nbsp;&nbsp;&nbsp;</p></div>
    <div align="center">
    <form name="editEmailContacts">
    <input type="hidden" value="<?php echo $record_row['record_id']; ?>" />
    <p><input type="text" name="additionalEmail" id="additionalEmail" value="Enter Email Address" />

    if ($record_row['record_additional_email_five'] != NULL) { ?>
    <select name="additionalEmailType" id="additionalEmailType"><option value="replace" label="Replace Current Contact"></option><option value="include" label="Include As CC" disabled="disabled"></option></select><br>
    The option to INCLUDE AS CC has been disabled, as there are already five additional email addresses for this record.</p>

    } else { ?>
    <select name="additionalEmailType" id="additionalEmailType"><option value="include" label="Include As CC"></option><option value="replace" label="Replace Current Contact"></option></select></p>

    } ?>
    <p><input type="submit" value="Update Email Contacts" onclick="editEmailContacts();" /> <input type="button" value="Nevermind" onclick="new Effect.SwitchOff('editEmail');" /></p>
    <table width="100%" cellspacing="0" class="menuBar">
    <tr class="darkBG">
    <td align="center"><input type="button" value="Update Status" onclick="new Effect.Appear('editStatus');" /></td>
    <td align="center"><input type="button" value="Edit Email Contacts" onclick="new Effect.Appear('editEmail');" /></td>
    <td align="center"><a href="history.php"><input type="button" value="View History" /></a></td></tr>
    <br />
    <table width="100%" border="1" class="border" cellspacing="0" cellpadding="4">

    <?php //removed irrelevant parts of this table ?>

    <div id="contactEmail">Contact Email:<br />
    <a href="mailto:<?php echo $record_row['record_user_email'] ?>"><?php echo $record_row['record_user_email'] ?></a>
    <td colspan="3">
    <div id="additionalEmails">Additional Emails (5 max):<br />

    if ($record_row['record_additional_email_one'] == NULL) {
    echo "None Added";
    if ($record_row['record_additional_email_one'] != NULL) {
    echo "<a href=\"mailto:" . $record_row['record_additional_email_one'] . "\">" . $record_row['record_additional_email_one'] . "</a>";
    if ($record_row['record_additional_email_two'] != NULL) {
    echo ", <a href=\"mailto:" . $record_row['record_additional_email_two'] . "\">" . $record_row['record_additional_email_two'] . "</a>";
    if ($record_row['record_additional_email_three'] != NULL) {
    echo ", <a href=\"mailto:" . $record_row['record_additional_email_three'] . "\">" . $record_row['record_additional_email_three'] . "</a>";
    if ($record_row['record_additional_email_four'] != NULL) {
    echo ", <a href=\"mailto:" . $record_row['record_additional_email_four'] . "\">" . $record_row['record_additional_email_four'] . "</a>";
    if ($record_row['record_additional_email_five'] != NULL) {
    echo ", <a href=\"mailto:" . $record_row['record_additional_email_five'] . "\">" . $record_row['record_additional_email_five'] . "</a>";


  2. #2
    Join Date
    May 2007
    Thanked 0 Times in 0 Posts


    since i'm using scriptaculous, and thus prototype, i also checked into the ajax that comes with prototype too. i tried using it, same result. what am i doing wrong? when i click the button to initiate the ajax request, the hidden div goes away and the page looses all it's php variables. the information is not sent to my php script (which works by the way) and it's definitely not getting a response back because it's not running the line...

    new Effect.BlindUp('editEmail');

    i can post the js used for prototype attempt, but it's just copied right out of the manual. what am i doing wrong? thanks for any help you can offer!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts