Reputation: 1049
I am trying to get a value from a textbox and I'm only returning [object Object]
.
var key = $('body').on('click', '#ReportReferenceElectrical',function() {
$('#ReportReferenceElectrical').val();
});
var REPORTS_KEY = key;
I have tried the usual:
var key = $('#ReportReferenceElectrical').val();
The JS
is in an iife
and the value needs to retrieved when I submit the form to save but using this way its empty as the value was empty when the form loaded, I though the top code snippet might return me the value, but not.
Upvotes: 0
Views: 44
Reputation: 59262
The callback will get executed only when it is triggered. In this case, manually $.fn.trigger
ing isn't an option, I suppose as it will be ""
(Empty)
What you need is a callback.
function callback(key) {
alert(key);
// do something with the key now
}
And then call it in the event handler. I'd suggest going for the blur
event rather than click
$('body').on('blur', '#ReportReferenceElectrical',function() {
callback($('#ReportReferenceElectrical').val());
});
Upvotes: 1