Sascha Nickel Sascha Nickel - 27 days ago 6
Javascript Question

IE throws error on if statement

I have no idea why on IE, the code reports an error. Here is the code:

if ($size === null) {
$sizeFolder = '48x48';
} else $sizeFolder = $size+'x'+$size;


The error is as follows:

SCRIPTING1006: ')' expected


IE will set a
)
here like this :

if ($size === null)) {
$sizeFolder = '48x48';
} else $sizeFolder = $size+'x'+$size;


but this is still not working. Why is IE reporting an error?

here is the complete Code :

$.ttMessageBox.getIcon = function ($icon,$size=null) {
var $_icons = Array('[Information]','[Error]','[Question]','[OK]');
if ($size === null) {
$sizeFolder = '48x48';
} else $sizeFolder = $size+'x'+$size;
$result = '';
$Icon = $_icons.indexOf($icon);
switch ($Icon) {
case 0: $result += '<img src="/img/icons/'+$sizeFolder+'/dialog_information.png" />';
break;
case 1: $result += '<img src="/img/icons/'+$sizeFolder+'/dialog_error.png" />';
break;
case 2: $result += '<img src="/img/icons/'+$sizeFolder+'/dialog_question.png" />';
break;
case 3: $result += '<img src="/img/icons/'+$sizeFolder+'/dialog_check.png" />';
break;
default: $result += '';
}
return $result;
}

Answer

The error is on this line:

   $.ttMessageBox.getIcon = function ($icon,$size=null) {

IE does not support default values for function parameters. You can't have the =null bit.

Comments