Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
steelcity_ballin
Gerbilus Supremus
Topic Author
Posts: 12072
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Cross-browser Javascript annoyances

Tue Jan 13, 2009 10:14 am

I'm developing a rather complicated webpage that mixes technologies like javascript and vb.net, along with a javascript framework in mootools. I've had some bumps along the way but I'm *almost* there and now IE sucks the life out of me. Apparently the addEvent command does not work in IE because SURPRISE IE has once again decided to ignore WC3 standards and guidelines and do whatever the hell it wants. My code works exactly how I want it to in FF2 so far.

window.addEvent('domready', function() {      
      declareProps();
      for(i=0;i<numProps;i++){               
         tmpProp = "prop" + (i+1); // sets which div should slide in         
         tmpSelector = "ctl00_main_propSelector_"+(i); // sets which radiobutton to add event handler to
         
         //alert("i = " +i+ "\ntmpProp = " +tmpProp+ "\ntmpSelector = " + tmpSelector+ ".")            
         $(tmpSelector).addEvent('mouseup', function(e){            
            e.stop();            
            for(j=0;j<document.aspnetForm.ctl00$main$propSelector.length;j++){ // loop through all properties
               if(document.aspnetForm.ctl00$main$propSelector[j].checked){
                  alert("Property " +(j+1)+ " was checked.")
               }               
            }                                    
         });   
      }      
   });


According to my google-fu, the way IE handles it is via the "attachEvent" command, and instead of 'mouseup', it would be 'onmouseup'. The fun part is, it doesn't work. I don't get any errors, it just doesn't work. Ideas on how to attach an event like the above in ie? The obvious answer to my problem is to test the solution first like http://snipplr.com/view/3116/cross-brow ... -listener/ but again, doesn't work, no errors.
 
steelcity_ballin
Gerbilus Supremus
Topic Author
Posts: 12072
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Cross-browser Javascript annoyances

Tue Jan 13, 2009 10:55 am

As always, things are not what they seem. I have isolated the problem now, but do not know why it is a problem.

The problem is this line above
eval('prop' + (i+1) +' = new Fx.Slide("'+tmpVar+'")');


FF says it's cool, does it's thing. IE chokes on it. I tried rewriting it (as I thought perhaps the quotes were confusing poor ie) as
eval("prop" + (i+1) +" = new Fx.Slide('"+tmpVar+"')");

Among other combinations, ALL of which FF2 accepted and IE cried on. This line is important as it dynamically creates a variable name based on a loop iteration created from .Net criterion. The lightest weight even worked in FF, but again no dice in IE...

eval('prop' + (i+1) +' = new Fx.Slide(tmpVar)');


Been staring at it a while.
 
steelcity_ballin
Gerbilus Supremus
Topic Author
Posts: 12072
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Cross-browser Javascript annoyances

Tue Jan 13, 2009 11:34 am

So figured the problem out, not sure of the solution just yet. In IE you can't use a variable without using var first, so while everyone else is cool with it, ie is sticking to their guns and not allowing me to do it. Gah.

edit: The solution is adding "var" right after my eval statement. Swear to god i'm going to just open a notepad up and pretend to type on a forum, I always figures this crap out and it's always something silly I shouldn't known. Thanks anyhow, maybe someone learns something!

eval('var prop' + (i+1) +' = new Fx.Slide(tmpVar)');   

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On