MrAdam Posted December 4, 2006 Share Posted December 4, 2006 hi all, trying to create a little pop up that sends an email. i have the popup working fine, but the AJAX to open "sendemail.php" isn't working.here's my script: var xmlHttp;function sendEmail() { var eName = document.getElementById('eName').value; var eEmail = document.getElementById('eEmail').value; var eMessage = document.getElementById('eMessage').value; var xmlHttp = GetXmlHttpObject(); if (xmlHttp == null) { alert ("Sorry, your browser does not support HTTP requests. To use this feature please download a newer web browser. For now please use the contact page.") return; } var url = "sendemail.php"; url = url + "?eName=" + eName; url = url + "&eEmail=" + eEmail; url = url + "&eMessage=" + eMessage; url = url + "&sid=" + Math.random(); xmlHttp.onreadystatechange = updatePopUp; xmlHttp.open("GET",url,true); xmlHttp.send(null);}function updatePopUp() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById('popup').innerHTML=xmlHttp.responseText; } } function GetXmlHttpObject() { var objXMLHttp=null; if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); } return objXMLHttp;} anyone know why it isn't working? Just says "Error" in the status bar... Link to comment Share on other sites More sharing options...
MrAdam Posted December 4, 2006 Author Share Posted December 4, 2006 ahh, i've found the problem... var xmlHttp = GetXmlHttpObject(); Link to comment Share on other sites More sharing options...
MrAdam Posted December 4, 2006 Author Share Posted December 4, 2006 the finished result of what i've been needing help with over the past few days: http://www.newbiestyle.co.uk/lib/popups/email/(for anyone that cares) Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 5, 2006 Share Posted December 5, 2006 the finished result of what i've been needing help with over the past few days: http://www.newbiestyle.co.uk/lib/popups/email/(for anyone that cares)Doesn't work in FireFox :)When I click the button, nothing happens. Link to comment Share on other sites More sharing options...
MrAdam Posted December 5, 2006 Author Share Posted December 5, 2006 haha, CRAP! Link to comment Share on other sites More sharing options...
jesh Posted December 5, 2006 Share Posted December 5, 2006 This line always seems to cause problems: xmlHttp.send(null); Try doing this instead: xmlHttp.send(""); Link to comment Share on other sites More sharing options...
MrAdam Posted December 5, 2006 Author Share Posted December 5, 2006 still fails :Sit's not displaying the email box at all, so it's not a problem (yet) with the AJAX. Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 6, 2006 Share Posted December 6, 2006 still fails :Sit's not displaying the email box at all, so it's not a problem (yet) with the AJAX.In your top function, you haven't defined event. Try passing it through the onclick event of the button.<input type="button" onclick="popup(event)" />Like that. Link to comment Share on other sites More sharing options...
MrAdam Posted December 6, 2006 Author Share Posted December 6, 2006 yayer! one step closer! now part of it pops up since i added event (thankyou chocolate570!) but it is onlypart of it. looks like some kind of HTML error?updated link: http://www.newbiestyle.co.uk/lib/popups/email/-Thanks for your help guys! Link to comment Share on other sites More sharing options...
adservio Posted December 7, 2006 Share Posted December 7, 2006 You have a broken height attribute in your outter table.Also I would suggest moving your form tags out of the table. function displayPopUp(event) { var fromTop = event.clientY; var promptWidth = 400; var fromLeft = ((screen.width - promptWidth) / 2) - 21; if(!document.getElementById("prompt")) { var promptBox = document.createElement('div'); promptBox.id = 'prompt'; } else { var promptBox = document.getElementById('prompt'); } if(!document.getElementById("prompt")) document.body.appendChild(promptBox); promptBox.style.width = promptWidth; //promptBox.style.height = '300'; promptBox.style.backgroundColor = '#ffffff'; promptBox.style.border = '1px solid #476B8A'; promptBox.style.fontFamily = 'arial'; promptBox.style.fontSize = '10pt'; promptBox.style.position = 'absolute'; promptBox.style.top = fromTop; promptBox.style.left = fromLeft; promptBox.style.padding = '1px'; promptBox.innerHTML = '<form><table width="100%" border="0" cellpadding="0" cellspacing="0">\n' +'<tr>\n' +' <td width="93%" height="26" bgcolor="#6589A7"> <b>Send Email</b></td>\n' +' <td width="7%" height="26" bgcolor="#6589A7" style="padding:3px;">\n' +' <center><img src="close.gif" style="cursor:pointer;" onClick="closePopUp();" alt="Close Email Form" /></center>\n' +' </td>\n' +'</tr>\n' +'<tr>\n' +' <td colspan="2">\n' +' <div style="overflow:auto;padding:1px;background-color:#FEFFFF;" id="popup">\n' +' <table width="100%" border="0" cellpadding="5" cellspacing="0">\n' +' <tr>\n' +' <td width="50%">Your name:</td>\n' +' <td width="50%"><input type="text" id="eName" /></td>\n' +' </tr>\n' +' <tr>\n' +' <td width="50%">Your email:</td>\n' +' <td width="50%"><input type="text" id="eEmail" /></td>\n' +' </tr>\n' +' <tr>\n' +' <td width="50%">Your message:</td>\n' +' <td width="50%">\n' +' <textarea id="eMessage" style="width:200px;height:40px;"></textarea></td>\n' +' </tr>\n' +' </table></div>\n' +' </td></tr><tr><td colspan="2">\n' +' <hr color="#6589A7" size="1" />\n' +' <span style="text-align:right;width:100%">\n' +' <img align="right" src="send.gif" style="cursor:pointer;" onClick="sendEmail();" /></span>\n' +' </td>\n' +' </tr>\n' +'</table></form>\n';} HTH Link to comment Share on other sites More sharing options...
MrAdam Posted December 7, 2006 Author Share Posted December 7, 2006 YAYER! it finally works! thankyou all guys! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now