javascript call a function from another
I have this JS function:
function addMemberToLessonDirect(id)
{
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
method: 'POST',
url: '/admin/lessons/addMember/licenseMemberId',
data: {'licenseMemberId' : id},
success: function(response){
if ($.trim(response)) {
var actualMembers = document.getElementById("actual-member");
if (!$.trim(actualMembers)) {
$('#no_members').hide();
var div1 = document.createElement('div');
div1.setAttribute('class','table-responsive');
$('#space').append(div1);
var actualMembers = document.createElement('table');
actualMembers.setAttribute('class','table');
div1.append(actualMembers);
}
var newRow = actualMembers.insertRow(actualMembers.length);
newRow.setAttribute( "data-id",response['llm']['id']);
id = newRow.insertCell(0);
id.innerHTML = response['user_saved']['id'];
nip = newRow.insertCell(1);
nip.innerHTML = response['user_saved']['nip'];
update.innerHTML ="<a class='btn btn-info btn-xs edit' title='{{__('member.edit')}}'> <i class='fa fa-pencil'></i> </a>";
}
$('#membersModal').modal('hide');
},
error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
}
});
}
This function call or create a table (actual-member) and add rows and columns. This function is called when I choose an element from a modal that I have. When I choose the element in the modal this element will be appended to the table.
Now this table has also another JS function that make some of the fields editables and saveable:
$("#actual-member tr").editable({
keyboard: true,
dblclick: true,
button: true,
buttonSelector: ".edit",
dropdowns: {},
maintainWidth: true,
edit: function (values) {
$(".edit i", this)
.removeClass('fa-pencil')
.addClass('fa-save')
.attr('title', '{{__('member.save')}}');
},
save: function (values) {
values._token = '<?php echo csrf_token(); ?>';
//console.log(values);
var lessonLicenseMemberId = $(this).data('id');
$.post('/admin/lessons/editLessonLicenseMember/' + lessonLicenseMemberId, values);
},
cancel: function(values) {
$(".edit i", this)
.removeClass('fa-save')
.addClass('fa-pencil')
.attr('title', '{{__('member.edit')}}');
}
});
When I try to click the edit button in the table on an element not created with the addMemberToLessonDirect function it works well, but when I click on the same button on elements created by the addMemberToLessonDirect function nothing happens. I think that they don't have the "property" editable (second function).
Is it possible to call the editable function from the addMemberToLessonDirect function?
javascript jquery call
add a comment |
I have this JS function:
function addMemberToLessonDirect(id)
{
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
method: 'POST',
url: '/admin/lessons/addMember/licenseMemberId',
data: {'licenseMemberId' : id},
success: function(response){
if ($.trim(response)) {
var actualMembers = document.getElementById("actual-member");
if (!$.trim(actualMembers)) {
$('#no_members').hide();
var div1 = document.createElement('div');
div1.setAttribute('class','table-responsive');
$('#space').append(div1);
var actualMembers = document.createElement('table');
actualMembers.setAttribute('class','table');
div1.append(actualMembers);
}
var newRow = actualMembers.insertRow(actualMembers.length);
newRow.setAttribute( "data-id",response['llm']['id']);
id = newRow.insertCell(0);
id.innerHTML = response['user_saved']['id'];
nip = newRow.insertCell(1);
nip.innerHTML = response['user_saved']['nip'];
update.innerHTML ="<a class='btn btn-info btn-xs edit' title='{{__('member.edit')}}'> <i class='fa fa-pencil'></i> </a>";
}
$('#membersModal').modal('hide');
},
error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
}
});
}
This function call or create a table (actual-member) and add rows and columns. This function is called when I choose an element from a modal that I have. When I choose the element in the modal this element will be appended to the table.
Now this table has also another JS function that make some of the fields editables and saveable:
$("#actual-member tr").editable({
keyboard: true,
dblclick: true,
button: true,
buttonSelector: ".edit",
dropdowns: {},
maintainWidth: true,
edit: function (values) {
$(".edit i", this)
.removeClass('fa-pencil')
.addClass('fa-save')
.attr('title', '{{__('member.save')}}');
},
save: function (values) {
values._token = '<?php echo csrf_token(); ?>';
//console.log(values);
var lessonLicenseMemberId = $(this).data('id');
$.post('/admin/lessons/editLessonLicenseMember/' + lessonLicenseMemberId, values);
},
cancel: function(values) {
$(".edit i", this)
.removeClass('fa-save')
.addClass('fa-pencil')
.attr('title', '{{__('member.edit')}}');
}
});
When I try to click the edit button in the table on an element not created with the addMemberToLessonDirect function it works well, but when I click on the same button on elements created by the addMemberToLessonDirect function nothing happens. I think that they don't have the "property" editable (second function).
Is it possible to call the editable function from the addMemberToLessonDirect function?
javascript jquery call
what exactly you want to acheive
– manish kumar
Nov 22 '18 at 10:03
add a comment |
I have this JS function:
function addMemberToLessonDirect(id)
{
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
method: 'POST',
url: '/admin/lessons/addMember/licenseMemberId',
data: {'licenseMemberId' : id},
success: function(response){
if ($.trim(response)) {
var actualMembers = document.getElementById("actual-member");
if (!$.trim(actualMembers)) {
$('#no_members').hide();
var div1 = document.createElement('div');
div1.setAttribute('class','table-responsive');
$('#space').append(div1);
var actualMembers = document.createElement('table');
actualMembers.setAttribute('class','table');
div1.append(actualMembers);
}
var newRow = actualMembers.insertRow(actualMembers.length);
newRow.setAttribute( "data-id",response['llm']['id']);
id = newRow.insertCell(0);
id.innerHTML = response['user_saved']['id'];
nip = newRow.insertCell(1);
nip.innerHTML = response['user_saved']['nip'];
update.innerHTML ="<a class='btn btn-info btn-xs edit' title='{{__('member.edit')}}'> <i class='fa fa-pencil'></i> </a>";
}
$('#membersModal').modal('hide');
},
error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
}
});
}
This function call or create a table (actual-member) and add rows and columns. This function is called when I choose an element from a modal that I have. When I choose the element in the modal this element will be appended to the table.
Now this table has also another JS function that make some of the fields editables and saveable:
$("#actual-member tr").editable({
keyboard: true,
dblclick: true,
button: true,
buttonSelector: ".edit",
dropdowns: {},
maintainWidth: true,
edit: function (values) {
$(".edit i", this)
.removeClass('fa-pencil')
.addClass('fa-save')
.attr('title', '{{__('member.save')}}');
},
save: function (values) {
values._token = '<?php echo csrf_token(); ?>';
//console.log(values);
var lessonLicenseMemberId = $(this).data('id');
$.post('/admin/lessons/editLessonLicenseMember/' + lessonLicenseMemberId, values);
},
cancel: function(values) {
$(".edit i", this)
.removeClass('fa-save')
.addClass('fa-pencil')
.attr('title', '{{__('member.edit')}}');
}
});
When I try to click the edit button in the table on an element not created with the addMemberToLessonDirect function it works well, but when I click on the same button on elements created by the addMemberToLessonDirect function nothing happens. I think that they don't have the "property" editable (second function).
Is it possible to call the editable function from the addMemberToLessonDirect function?
javascript jquery call
I have this JS function:
function addMemberToLessonDirect(id)
{
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
method: 'POST',
url: '/admin/lessons/addMember/licenseMemberId',
data: {'licenseMemberId' : id},
success: function(response){
if ($.trim(response)) {
var actualMembers = document.getElementById("actual-member");
if (!$.trim(actualMembers)) {
$('#no_members').hide();
var div1 = document.createElement('div');
div1.setAttribute('class','table-responsive');
$('#space').append(div1);
var actualMembers = document.createElement('table');
actualMembers.setAttribute('class','table');
div1.append(actualMembers);
}
var newRow = actualMembers.insertRow(actualMembers.length);
newRow.setAttribute( "data-id",response['llm']['id']);
id = newRow.insertCell(0);
id.innerHTML = response['user_saved']['id'];
nip = newRow.insertCell(1);
nip.innerHTML = response['user_saved']['nip'];
update.innerHTML ="<a class='btn btn-info btn-xs edit' title='{{__('member.edit')}}'> <i class='fa fa-pencil'></i> </a>";
}
$('#membersModal').modal('hide');
},
error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
}
});
}
This function call or create a table (actual-member) and add rows and columns. This function is called when I choose an element from a modal that I have. When I choose the element in the modal this element will be appended to the table.
Now this table has also another JS function that make some of the fields editables and saveable:
$("#actual-member tr").editable({
keyboard: true,
dblclick: true,
button: true,
buttonSelector: ".edit",
dropdowns: {},
maintainWidth: true,
edit: function (values) {
$(".edit i", this)
.removeClass('fa-pencil')
.addClass('fa-save')
.attr('title', '{{__('member.save')}}');
},
save: function (values) {
values._token = '<?php echo csrf_token(); ?>';
//console.log(values);
var lessonLicenseMemberId = $(this).data('id');
$.post('/admin/lessons/editLessonLicenseMember/' + lessonLicenseMemberId, values);
},
cancel: function(values) {
$(".edit i", this)
.removeClass('fa-save')
.addClass('fa-pencil')
.attr('title', '{{__('member.edit')}}');
}
});
When I try to click the edit button in the table on an element not created with the addMemberToLessonDirect function it works well, but when I click on the same button on elements created by the addMemberToLessonDirect function nothing happens. I think that they don't have the "property" editable (second function).
Is it possible to call the editable function from the addMemberToLessonDirect function?
javascript jquery call
javascript jquery call
asked Nov 22 '18 at 9:53
m.Sartom.Sarto
395
395
what exactly you want to acheive
– manish kumar
Nov 22 '18 at 10:03
add a comment |
what exactly you want to acheive
– manish kumar
Nov 22 '18 at 10:03
what exactly you want to acheive
– manish kumar
Nov 22 '18 at 10:03
what exactly you want to acheive
– manish kumar
Nov 22 '18 at 10:03
add a comment |
1 Answer
1
active
oldest
votes
The elements which are created with addMemberToLessonDirect
are created asynchronously from the ajax
callback. That means that you don't really know when they are available for the DOM
- and for sure they are not avaialble when you call $("#actual-member tr").editable({...
. which I assume is somewhere in your code which is executed synchronously.
You do know they are availalbe when the callback is executed after the ajax
call, in the success: function(response){ ...
callback.
Per this, What you need to do is add the same logic as in $("#actual-member tr").editable({
to the callback return in success: function(response){ ..
I created this ajax function in $("#actual-member tr").editable: $.ajax({ method: 'POST', url: '/admin/lessons/editLessonLicenseMember/'+values.id, data: {'notes' : values.notes}, success: function(response){ }, error: function(jqXHR, textStatus, errorThrown) { } }); but how can I make the button work?
– m.Sarto
Nov 22 '18 at 13:03
You need to put the required code which effects the elements returned from theaddMemberToLessonDirect
ajax
call inside the callback function which is insuccess: function(response){ ...
– Alon Adler
Nov 22 '18 at 13:10
the $("#actual-member tr").editable({ becomes from a JS plugin (jqueryscript.net/demo/…). Do you mean that I have to modify the plugin source code? I'm a bit confused...
– m.Sarto
Nov 23 '18 at 8:55
No, you need to make the updates to the rows created by theajax
call after they are created, which means inside thesuccess: function(response){
function.
– Alon Adler
Nov 25 '18 at 9:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428203%2fjavascript-call-a-function-from-another%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The elements which are created with addMemberToLessonDirect
are created asynchronously from the ajax
callback. That means that you don't really know when they are available for the DOM
- and for sure they are not avaialble when you call $("#actual-member tr").editable({...
. which I assume is somewhere in your code which is executed synchronously.
You do know they are availalbe when the callback is executed after the ajax
call, in the success: function(response){ ...
callback.
Per this, What you need to do is add the same logic as in $("#actual-member tr").editable({
to the callback return in success: function(response){ ..
I created this ajax function in $("#actual-member tr").editable: $.ajax({ method: 'POST', url: '/admin/lessons/editLessonLicenseMember/'+values.id, data: {'notes' : values.notes}, success: function(response){ }, error: function(jqXHR, textStatus, errorThrown) { } }); but how can I make the button work?
– m.Sarto
Nov 22 '18 at 13:03
You need to put the required code which effects the elements returned from theaddMemberToLessonDirect
ajax
call inside the callback function which is insuccess: function(response){ ...
– Alon Adler
Nov 22 '18 at 13:10
the $("#actual-member tr").editable({ becomes from a JS plugin (jqueryscript.net/demo/…). Do you mean that I have to modify the plugin source code? I'm a bit confused...
– m.Sarto
Nov 23 '18 at 8:55
No, you need to make the updates to the rows created by theajax
call after they are created, which means inside thesuccess: function(response){
function.
– Alon Adler
Nov 25 '18 at 9:55
add a comment |
The elements which are created with addMemberToLessonDirect
are created asynchronously from the ajax
callback. That means that you don't really know when they are available for the DOM
- and for sure they are not avaialble when you call $("#actual-member tr").editable({...
. which I assume is somewhere in your code which is executed synchronously.
You do know they are availalbe when the callback is executed after the ajax
call, in the success: function(response){ ...
callback.
Per this, What you need to do is add the same logic as in $("#actual-member tr").editable({
to the callback return in success: function(response){ ..
I created this ajax function in $("#actual-member tr").editable: $.ajax({ method: 'POST', url: '/admin/lessons/editLessonLicenseMember/'+values.id, data: {'notes' : values.notes}, success: function(response){ }, error: function(jqXHR, textStatus, errorThrown) { } }); but how can I make the button work?
– m.Sarto
Nov 22 '18 at 13:03
You need to put the required code which effects the elements returned from theaddMemberToLessonDirect
ajax
call inside the callback function which is insuccess: function(response){ ...
– Alon Adler
Nov 22 '18 at 13:10
the $("#actual-member tr").editable({ becomes from a JS plugin (jqueryscript.net/demo/…). Do you mean that I have to modify the plugin source code? I'm a bit confused...
– m.Sarto
Nov 23 '18 at 8:55
No, you need to make the updates to the rows created by theajax
call after they are created, which means inside thesuccess: function(response){
function.
– Alon Adler
Nov 25 '18 at 9:55
add a comment |
The elements which are created with addMemberToLessonDirect
are created asynchronously from the ajax
callback. That means that you don't really know when they are available for the DOM
- and for sure they are not avaialble when you call $("#actual-member tr").editable({...
. which I assume is somewhere in your code which is executed synchronously.
You do know they are availalbe when the callback is executed after the ajax
call, in the success: function(response){ ...
callback.
Per this, What you need to do is add the same logic as in $("#actual-member tr").editable({
to the callback return in success: function(response){ ..
The elements which are created with addMemberToLessonDirect
are created asynchronously from the ajax
callback. That means that you don't really know when they are available for the DOM
- and for sure they are not avaialble when you call $("#actual-member tr").editable({...
. which I assume is somewhere in your code which is executed synchronously.
You do know they are availalbe when the callback is executed after the ajax
call, in the success: function(response){ ...
callback.
Per this, What you need to do is add the same logic as in $("#actual-member tr").editable({
to the callback return in success: function(response){ ..
answered Nov 22 '18 at 10:04
Alon AdlerAlon Adler
2,70532438
2,70532438
I created this ajax function in $("#actual-member tr").editable: $.ajax({ method: 'POST', url: '/admin/lessons/editLessonLicenseMember/'+values.id, data: {'notes' : values.notes}, success: function(response){ }, error: function(jqXHR, textStatus, errorThrown) { } }); but how can I make the button work?
– m.Sarto
Nov 22 '18 at 13:03
You need to put the required code which effects the elements returned from theaddMemberToLessonDirect
ajax
call inside the callback function which is insuccess: function(response){ ...
– Alon Adler
Nov 22 '18 at 13:10
the $("#actual-member tr").editable({ becomes from a JS plugin (jqueryscript.net/demo/…). Do you mean that I have to modify the plugin source code? I'm a bit confused...
– m.Sarto
Nov 23 '18 at 8:55
No, you need to make the updates to the rows created by theajax
call after they are created, which means inside thesuccess: function(response){
function.
– Alon Adler
Nov 25 '18 at 9:55
add a comment |
I created this ajax function in $("#actual-member tr").editable: $.ajax({ method: 'POST', url: '/admin/lessons/editLessonLicenseMember/'+values.id, data: {'notes' : values.notes}, success: function(response){ }, error: function(jqXHR, textStatus, errorThrown) { } }); but how can I make the button work?
– m.Sarto
Nov 22 '18 at 13:03
You need to put the required code which effects the elements returned from theaddMemberToLessonDirect
ajax
call inside the callback function which is insuccess: function(response){ ...
– Alon Adler
Nov 22 '18 at 13:10
the $("#actual-member tr").editable({ becomes from a JS plugin (jqueryscript.net/demo/…). Do you mean that I have to modify the plugin source code? I'm a bit confused...
– m.Sarto
Nov 23 '18 at 8:55
No, you need to make the updates to the rows created by theajax
call after they are created, which means inside thesuccess: function(response){
function.
– Alon Adler
Nov 25 '18 at 9:55
I created this ajax function in $("#actual-member tr").editable: $.ajax({ method: 'POST', url: '/admin/lessons/editLessonLicenseMember/'+values.id, data: {'notes' : values.notes}, success: function(response){ }, error: function(jqXHR, textStatus, errorThrown) { } }); but how can I make the button work?
– m.Sarto
Nov 22 '18 at 13:03
I created this ajax function in $("#actual-member tr").editable: $.ajax({ method: 'POST', url: '/admin/lessons/editLessonLicenseMember/'+values.id, data: {'notes' : values.notes}, success: function(response){ }, error: function(jqXHR, textStatus, errorThrown) { } }); but how can I make the button work?
– m.Sarto
Nov 22 '18 at 13:03
You need to put the required code which effects the elements returned from the
addMemberToLessonDirect
ajax
call inside the callback function which is in success: function(response){ ...
– Alon Adler
Nov 22 '18 at 13:10
You need to put the required code which effects the elements returned from the
addMemberToLessonDirect
ajax
call inside the callback function which is in success: function(response){ ...
– Alon Adler
Nov 22 '18 at 13:10
the $("#actual-member tr").editable({ becomes from a JS plugin (jqueryscript.net/demo/…). Do you mean that I have to modify the plugin source code? I'm a bit confused...
– m.Sarto
Nov 23 '18 at 8:55
the $("#actual-member tr").editable({ becomes from a JS plugin (jqueryscript.net/demo/…). Do you mean that I have to modify the plugin source code? I'm a bit confused...
– m.Sarto
Nov 23 '18 at 8:55
No, you need to make the updates to the rows created by the
ajax
call after they are created, which means inside the success: function(response){
function.– Alon Adler
Nov 25 '18 at 9:55
No, you need to make the updates to the rows created by the
ajax
call after they are created, which means inside the success: function(response){
function.– Alon Adler
Nov 25 '18 at 9:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428203%2fjavascript-call-a-function-from-another%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what exactly you want to acheive
– manish kumar
Nov 22 '18 at 10:03