Jump to content

ajax newb, took tute, not working


Guest ahs10
 Share

Recommended Posts

so i'm new to ajax, took the tutorial and it's not working for me. i have a form (name="editEmailContacts") in a hidden div (made viewable by scriptaculous) that calls the js function editEmailContacts() via onclick of the submit button. after the ajax, i have the line....new Effect.BlindUp('editEmail');...which hides the div again. this line isn't being executed, which is why i don't think my request is even being sent to my php script. my php script does work by the way... it's getting vars via get and if i run the script by typing out the url in a browser, it does as it should.any help is much appreciated. i've posted my code below, removing irrelevant parts. thanks for taking the time to even read it. i'll put you on my christmas card list if you can solve my problem :)<?phpsession_cache_limiter('nocache');include("php/dbConnect.php");$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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><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 xmlHttpfunction editEmailContacts() { xmlHttp=GetXmlHttpObject()if (xmlHttp==null) {alert ("You are using an incompatible browser.")return}var type=document.getElementById('additionalEmailType').valuevar email=document.getElementById('additionalEmail').valuevar url="editEmail.php"url=url+"?email="+emailurl=url+"&type="+typeurl=url+"&recordID"+<?php echo $recordID; ?>url=url+"&sid="+Math.random()xmlHttp.onreadystatechange=stateChanged(type)xmlHttp.open("GET",url,true)xmlHttp.send(null)}function stateChanged(type) { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {if (type=="replace") {document.getElementById("contactEmail").innerHTML=xmlHttp.responseText}if (type=="include") {document.getElementById("additionalEmails").innerHTML=xmlHttp.responseText}new Effect.BlindUp('editEmail'); } }function GetXmlHttpObject() {var xmlHttp=null;xmlHttp=new XMLHttpRequest();return xmlHttp;}</script></head><body><?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   </p></div><div align="center"><form name="editEmailContacts"><input type="hidden" value="<?php echo $record_row['record_id']; ?>" name="email" /><p><input type="text" name="additionalEmail" id="additionalEmail" value="Enter Email Address" /><?phpif ($record_row['record_additional_email_five'] != NULL) { ?><select name="type" 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><?php} else { ?><select name="type" id="additionalEmailType"><option value="include" label="Include As CC"></option><option value="replace" label="Replace Current Contact"></option></select></p><?php} ?><p><input type="submit" value="Update Email Contacts" onclick="editEmailContacts();" /> <input type="button" value="Nevermind" onclick="new Effect.SwitchOff('editEmail');" /></p></form></div></div><table width="100%" cellspacing="0" class="menuBar"><tr><td> </td></tr><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></table><br /><table width="100%" border="1" class="border" cellspacing="0" cellpadding="4"><?php //removed irrelevant parts of this table ?><tr><td><div id="contactEmail">Contact Email:<br /><a href="mailto:<?php echo $record_row['record_user_email'] ?>"><?php echo $record_row['record_user_email'] ?></a></div></td><td colspan="3"><div id="additionalEmails">Additional Emails (5 max):<br /><?phpif ($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>";}?></div></td></tr></table>

Link to comment
Share on other sites

This line isn't doing the right thing:xmlHttp.onreadystatechange=stateChanged(type)You're executing the stateChanged function, not assigning it as an event handler. If you want to use an event handler with a parameter you need to do it like this:xmlHttp.onreadystatechange = function() { stateChanged(type) };

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...