views:

4598

answers:

5

IE8 throws an "Error: Object required" message (error in the actual jquery library script, not my javascript file) when the switch statement in this function runs. This code works in IE6, IE7, FF3, and Safari... Any ideas? Does it have something to do with the '$(this)' selector in the switch? Thanks!

function totshirts(){
    $('.shirt-totals input').val('0');
    var cxs = 0;
    var cs = 0;
    var cm = 0;
    $.each($('select.size'), function() {
     switch($(this).val()){
      case "cxs":
       cxs ++;
       $('input[name="cxs"]').val(cxs);
       break;
      case "cs":
       cs ++;
       $('input[name="cs"]').val(cs);
       break;
      case "cm":
       cm ++;
       $('input[name="cm"]').val(cm);
       break;
     }
    });
}
+2  A: 

Oh noes, don't do it that way at all.

Do something more along the lines of this:

$('.shirt-totals input').val('0');
$('select.size').each(function() {
 var name = $(this).attr('name');
 var currVal = parseInt($("input[name='"+name+"']").val());
 $("input[name='"+name+"']").val(currVal+1);
});

As a sidenote, I tend to find that jQuery seems to deal with single quotes better than doubles in when doing the "equals" comparison.

altCognito
+1  A: 

I upgraded the jQuery library from 1.2.6 to 1.3.2 and this solved the problem. Didn't realize I had an old version- oops.

Thanks for your help all!

thechrisvoth
A: 

Hi all,

I change the version and no solve the problems :(

Any ideas ????

If you're not trying to run the toshirts() function cited in the question above, you might get a better response if you create a new question and provide specific details about your particular situation.
Readonly
A: 

Me too... I have the latest jQuery version, a very standard jQuery. I don´t know why, but IE8 does not load the jQuery library.

Fernando
A: 

Hey but I'm using Jquery version 1.4.2 But a small code just doesn't work on it. though its workin on IE7 but not on IE8

<script type="text/javascript" src="js/jquery.js"></script>

<SCRIPT language="JavaScript">
<!--

if (document.images)
{
  preload_image_object = new Image();
  // set image url
  image_url = new Array();
  image_url[0] = "images/random/0.png";
  image_url[1] = "images/random/1.png";
  image_url[2] = "images/random/2.png";
  image_url[3] = "images/random/3.png";
    image_url[4] = "images/random/4.png";

   var i = 0;
   for(i=0; i<=3; i++) 
     preload_image_object.src = image_url[i];
}

//-->
</SCRIPT>
 <script type="application/x-javascript">
 var $j = jQuery.noConflict();
     function rz()
     {
              var rn=Math.floor(Math.random()*5);
              //alert(rn);
              path  = "images/random/"+rn+".png";
              img = "<img src='"+path+"'"+">";
              $j(".update").empty();
            $j(".update"). append(img);
            $j(".update").fadeIn("slow");


     }
 </script>
bluepicaso