I want to write a simple function that will display an alert after sending the form, but I'm doing something wrong. Here is my code:
$(function() {
var alert_container = $('<div class="alert"></div>');
var alert = {
"success": "Success",
"error": "Error"
};
function show_message(msg) {
alert_container
.addClass(msg)
.append('<p>'+alert.msg+'</p>');
alert_container.insertBefore($("form")).hide().fadeIn(300);
}
$('form').on('submit', function(e) {
e.preventDefault();
show_message('success');
});
});
This code returns to me undefined inside alert box, but if i check console.log(alert.success) returns correct value which is "Success". What am I missing here?