Reputation: 1024
I have a textarea box to show notes from db. This box data is saved using following submit
button :
<button class="submit" id="save_note" value="save_note" onclick="edit_notebox(this,event);"><b>Save Note</b></button>
Now I am trying to show alert message if all following condition is fill up :
if above 3 conditions is true or fulfill then I want to show alert message.
So, for that I am using following code but not working:
Js Code :
var is_clicked = $("#save_note").val();
var previousValue = $("#project_notes").val();
$("#project_notes").blur(function(e) {
var currentValue = $(this).val();
if( currentValue != previousValue && is_clicked != 'save_note' ) {
previousValue = currentValue;
alert("Value changed!");
}
});
How can I get alert message based on above 3 condition ?
Upvotes: 0
Views: 98
Reputation: 9593
You could do something along these lines using a boolean variable:
var is_clicked = false;
var previousValue = $("#project_notes").val();
// Use mousedown instead of click so that it fires before the blur
$('.submit').on('mousedown', function(){
is_clicked = true; // Click happened
});
$("#project_notes").blur(function(e) {
var currentValue = $(this).val();
if (currentValue != previousValue && !is_clicked) {
previousValue = currentValue;
alert("Value changed!");
}
is_clicked = false; // Reset to catch next button click
});
Upvotes: 1