views:

62

answers:

1

For some reason in ie8 when I run this function after an onclick event it causes a page refresh. I don't wan the page refresh to happen.

   var edealsButton = dojo.byId("edeals_button");
   var edealEmailInput = dojo.byId("edeals_email");
   var edealsSignup = dojo.byId("edeals_signup");
   var edealsThankYou = dojo.byId("edeals_thankyou");
   var currentValue = dojo.attr(edealEmailInput, 'value');
   if (currentValue != '' && currentValue != 'Enter your email') {
       var anim = dojox.fx.flip({
           node: edealsSignup,
           dir: "right",
           duration: 300
       })
       dojo.connect(anim, "onEnd", this, function() {
           edealsSignup.style.display = "none";
           edealsThankYou.style.display = "block";
       })
       dojo.connect(anim, "onBegin", this, function() {

           var criteria = { "emailAddress": '"' + currentValue + '"' };
           alert("currentValue " + currentValue);
           var d = essentials.CallWebserviceMethod('AlmondForms.asmx/SignupEdeal', criteria);
           d.addCallback(function(response) {
               var obj = dojo.fromJson(response);
               alert(obj.d);
               if (obj != null && obj.d != null) {
                   //alert(obj.d);
                   if (obj.d == false)
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       alert("edealError: " + edealError);
                       dojo.style(edealSuccess, "display", "none");
                       dojo.style(edealError, "display", "inline-block");
                   }
                   else
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       dojo.style(edealSuccess, "display","inline-block");
                       dojo.style(edealError, "display", "none");
                   }
               }
               else {
                   var edealSuccess = dojo.byId("edeals_succes_thankyou");
                   var edealError = dojo.byId("edeals_error_thankyou");

                   dojo.style(edealSuccess, "display", "none");
                   dojo.style(edealError, "display", "inline-block");
               }
           });
       })
       anim.play();
       edealEmailInput.innerHTML == 'Enter your email';
   } 
   else 
   {
       dojo.attr(edealEmailInput, 'value', 'Enter your email');
       dojo.style(edealEmailInput, 'color', '#CC2525');
   }
A: 

It looks like your "d.addCallback" code might not be disposed of properly. You might want to try placing "dojo.stopEvent()" possibly before the "anim.play();" line and see if this would stop the postback.

From the api.dojotoolkit.org site, the dojo.stopEvent() "prevents propagation and clobbers the default action of the passed event". From the docs.dojocampus.org site, they say that "dojo.stopEvent(event) will prevent both default behavior any any propagation (bubbling) of an event."

Good luck, and hope this helps you out some.

Chris
I was missing the dojo.stopEvent(evt) and therefore the page was running the dojo and then doing a refresh as if a form button was pressed.The dojo.stopEvent(evt) prevented the page from doing it's page refresh on a form submit button.
Benny