Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
AJAX Prototype manually fired events

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
dennish
New one
New one


Joined: 05 Dec 2007
Posts: 1

PostPosted: Wed Dec 05, 2007 1:32 pm    Post subject: AJAX Prototype manually fired events Reply with quote

Hello all,

I've recently encountered a problem with my Web application that I can't figure out.

I'm using the Prototype JS library for AJAX, and PHP for the backend.

It seems that when I fire an event (onclick, onchange, onblur, focus, etc) via JavaScript to call the AJAX function, it doesn't send a header and it dosen't receive a response from the server. However, it works fine if the event is fired manually.

Here is how I am firing the onchange() event in both cases:

Manual - changing the value in the text box and pressing tab
JavaScript - from a pop-up window
Code:

<span onclick="window.opener.document.getElementById(elem).value='test';window.opener.document.getElementById(elem).onchange();window.close()">23</span>

They both trigger the function, because the database gets updated in both situations, however in the case of JavaScript event firing I'm not getting a response back.

Here is one of my AJAX functions
Code:

function doSaveAwardDate(qID) {
   var awardDate = $('awardDateTxt' + qID).value;
   //Parse date string
   var dateArray = awardDate.split('/');
   //Build date string for db input, yyyy/mm/dd
   var dateString = dateArray[2] + '/' + dateArray[0] + '/' + dateArray[1];
   dateString = encodeURIComponent(dateString);
   var quoteID = encodeURIComponent(qID);
   var awardDateURL = "";
   var param = "quoteID=" + quoteID + "&awardDate=" + dateString;

   //Do the AJAX call to save the changes to the award date
   new Ajax.Request(awardDateURL, {
      method: 'post',
      parameters: param,
      onComplete: function(transport) {
         if(transport.responseText == "ok") {
            alert('Award date successfully saved.');
         }
         else {
            alert('Error while updating award date: ' + transport.responseText);
         }
      }
   });      
}

Can anyone shed some light on this problem? Thank you.

Update: I've tried to debug it some more and found that if I return false from the child window, I get a response from my AJAX call. But the problem is that if I return false, then I can't close the window afterwards.
Back to top
View user's profile Send private message
Jesdisciple
Frequent Poster
Frequent Poster


Joined: 20 Oct 2007
Posts: 36
Location: Tejas

PostPosted: Thu Dec 06, 2007 3:23 pm    Post subject: Reply with quote

I'm not sure how to piece this together, so if you see this while I'm working on it, please clarify.

EDIT: Okay, I've modified what you gave to produce these two pages:

index.html:
Code:
<html>
   <head>
      <title>Titled Document</title>
      <script type="text/javascript" src="../../library/js/prototype.js"></script>
      <script type="text/javascript">
         function doSaveAwardDate(qID) {
            var awardDate = $('awardDateTxt' + qID).value;
            //Parse date string
            var dateArray = awardDate.split('/');
            //Build date string for db input, yyyy/mm/dd
            var dateString = dateArray[2] + '/' + dateArray[0] + '/' + dateArray[1];
            dateString = encodeURIComponent(dateString);
            var quoteID = encodeURIComponent(qID);
            var awardDateURL = '';
            var param = 'quoteID=' + quoteID + '&awardDate=' + dateString;
            
            //Do the AJAX call to save the changes to the award date
            new Ajax.Request(awardDateURL, {
                  method: 'post',
                  parameters: param,
                  onComplete: function(transport) {
                     if(transport.responseText == "ok") {
                        alert('Award date successfully saved.');
                     }else{
                        alert('Error while updating award date: ' + transport.responseText);
                     }
                  }
               });
         }
         function main(){
            var win = window.open('popup.html');
         }
      </script>
   </head>
   <body onload="main();">
      <input type="text" id="elem" onchange="doSaveAwardDate();">
   </body>
</html>


popup.html
[/code]<html>
<head>
<title>Titled Document</title>
<script type="text/javascript" src="../../library/js/prototype.js"></script>
</head>
<body>
<a onclick="javascript:window.opener.document.getElementById('elem').value='test'; window.opener.document.getElementById('elem').onchange(); window.close();">23</span>
</body>
</html>
Code:


And [url=http://www.getfirebug.com/]Firebug[/url] gives this error because no element with such an ID exists:[quote]$("awardDateTxt" + qID) has no properties
http://localhost/help/eventFiring/index.html
Line 7[/quote]

So I need more info!  (I would keep fiddling with this, but I'm behind on helping others.)[/quote]

_________________
In ALL things, strive for ><>,
Chris
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert