tags:

views:

19

answers:

2

There is Json array and i am using it to display my error messages.

var errorMessages {
"E1":"Error Occured During Request Processing...",  
"E2":" Enter User Name"
}

Next i want to display error messages base on error id

function showMessage(errorId){
    $('#serverMsg').html('');
    var msg = $('#messageContainer');        
    if (errorId.length != 0) {
            $('#messageContainer').show();
            $('#serverMsg').html(errorMessages.errorId);
    }   
    $("#messageContainer").focus(); 
}

it gives me undfine.

A: 

Instead of

$('#serverMsg').html(errorMessages.errorId);

try this

$('#serverMsg').html(errorMessages[errorId]);
Daniel A. White
he its working thanks
please at least mark my answer as accepted if this solved your problem. thanks.
Daniel A. White
+2  A: 

Perhaps you mean:

var errorMessages = {
  "E1": "Error Occured During Request Processing...",  
  "E2": " Enter User Name"
};

Also as Daniel said below make sure you realize that errorMessages doesn't have a property called errorId, if you want to use errorId to 'look up' the right message then you have to write it like:

errorMessages[errorId]
thenduks
I think its a combination of both.
Daniel A. White
Good catch.~~~~
Alex Bagnolini