views:

52

answers:

2

I am using the following code to open a modal box when a button is clicked. Works fine in all browsers but IE7 where I get an error.

This is the code. Have I done something wrong???

            <script type="text/javascript">
$(document).ready(function(){
var dialogOpts = {
      modal: true,
      bgiframe: true,
      autoOpen: false,
      height: 550,
      width: 550,
      draggable: true,
      resizeable: true,
      title: "Invite a friend",
   };
$("#invitebox").dialog(dialogOpts);   //end dialog

   $('#invitebutton').click(
      function() {
         $("#invitebox").load("widgets/invite_a_friend/index.php", [], function(){
               $("#invitebox").dialog("open");
            }
         );
         return false;
      }
   );
}); 
</script>
+3  A: 

Remove the , at the end after title:

var dialogOpts = {
      modal: true,
      bgiframe: true,
      autoOpen: false,
      height: 550,
      width: 550,
      draggable: true,
      resizeable: true,
      title: "Invite a friend", // <-- REMOVE THIS COMMA
   };

Also the .load() function takes an object and not array as second argument:

$("#invitebox").load("widgets/invite_a_friend/index.php", { }, function() {
    $("#invitebox").dialog("open");
});
Darin Dimitrov
Just FYI: commas at the end are only problematic in IE. My opinion is that with this issue IE is doing it the right way. Others are not. Code errors shouldn't be tolerated.
Robert Koritnik
@Robert, I completely disagree with you. This is not issue in IE. Javascript is an ECMA standard that programmers should respect. The fact that you can feed crap to other browsers and they accept it doesn't mean they are any better than IE. Accepting errors silently is even worst than notifying you as early as possible.
Darin Dimitrov
@Darin: That's exactly what I just said. I did say that other browsers are crap in this regard, because they just ignore this error, which is not right. I actually applauded IE on this. I guess you misunderstood me Darin. but as much as we praise this IE feature it should still be better handled, because you don't really get an error. It just ignores your script. This could be improved as well.
Robert Koritnik
@Robert, I am sorry, you modified your original comment. Ignore my comment in this case.
Darin Dimitrov
@Darin: My edit was done just because of the misspelled word "comas" to put an extra M inside. Everything else was left as it was. It's not nice to just come up with some obscure excuse for your own mistake of not fully reading the comment.
Robert Koritnik
@Robert if this is the case I apologize.
Darin Dimitrov
+1  A: 

Here is the problem, the comma at the end:

  title: "Invite a friend",
};

JSLint can tell you whether your code is correct.

Sjoerd