I’m working on my comment system for my website and I am not able to retrieve the value of the whole field.
I am using this script https://github.com/podio/jquery-mentions-input
return {
init : function (options) {
settings = options;
initTextarea();
initAutocomplete();
initMentionsOverlay();
},
val : function (callback) {
if (!_.isFunction(callback)) {
return;
}
var value = mentionsCollection.length ? elmInputBox.data('messageText') : getInputBoxValue();
callback.call(this, value);
}
}
The function val is the one returning the value !
This is the code that i’m using to get the value. (it doesn’t work)
$('#commentInput').mentionsInput('val', function(comment){ var test = comment; });
alert( test );
I would like to find a way to extract the value comment/test out of this function so it can be then sent to my database.
If I use this next code the alert box displays the good info.
('#commentInput').mentionsInput('val', function(comment) { alert(comment); });
I tried a few other manipulations to try and make it work, but I was always getting errors like [object Object] or [ HTMLDivElement]
I’m pretty sure it is something stupidly easy, but I cannot figure it out.
Hope someone could help me
Have a good day
Joris
Joris,
('#commentInput').mentionsInput('val', function(comment) { alert(comment); });is the correct formulation. You just need to go a step further, as follows:where
sendToDatabaseis a function that accepts a comment as its argument and uploads it (via ajax and a server script) to your database …. something like this: