get value from function inside function jquery [duplicate]

Multi tool use
Multi tool use





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0
















This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers




I'm really stuck with getting a value from this function, my guess is that it is because of the functions inside the functions.



(ps. I know I don't have to use quotes when I want to get a BOOL value)



Please help



$(document).ready(function() {    
var text = null;

function textCheck() {
if ($('.window-' + sc).has('input[type="text"]')) {
$(this).find('input[type="text"]').each(function() {
$(this).on('click', function() {
if ($(this).attr('required')) {
var placeholder = $(this).attr('original');

if (!$(this).val() == '') {
$(this).removeClass('is-invalid shake').addClass('is-valid').attr('placeholder', placeholder);
text = 'true';
//return text;
} else {
$(this).addClass('is-invalid shake').attr('placeholder', placeholder + " can't be empty");
text = 'false';
//return text;
};
};

});
});
};
return text;
};

var texxt = textCheck();
console.log(texxt);
});









share|improve this question















marked as duplicate by Quentin javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 0:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Logic is flawed. The value of text gets assigned after user clicks on an <input>. You can't access it until that occurs.

    – charlietfl
    Nov 22 '18 at 0:25













  • The "$(this).on('click', function() {" is getting in your way. This looks like a validation function, but you are binding an event handler which won't fire till the user clicks something. Try removing the binding and see if that helps.

    – Sage
    Nov 22 '18 at 0:26











  • even if i comment out the click function i still get 'undefined' response..

    – RMCS
    Nov 22 '18 at 15:46


















0
















This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers




I'm really stuck with getting a value from this function, my guess is that it is because of the functions inside the functions.



(ps. I know I don't have to use quotes when I want to get a BOOL value)



Please help



$(document).ready(function() {    
var text = null;

function textCheck() {
if ($('.window-' + sc).has('input[type="text"]')) {
$(this).find('input[type="text"]').each(function() {
$(this).on('click', function() {
if ($(this).attr('required')) {
var placeholder = $(this).attr('original');

if (!$(this).val() == '') {
$(this).removeClass('is-invalid shake').addClass('is-valid').attr('placeholder', placeholder);
text = 'true';
//return text;
} else {
$(this).addClass('is-invalid shake').attr('placeholder', placeholder + " can't be empty");
text = 'false';
//return text;
};
};

});
});
};
return text;
};

var texxt = textCheck();
console.log(texxt);
});









share|improve this question















marked as duplicate by Quentin javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 0:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Logic is flawed. The value of text gets assigned after user clicks on an <input>. You can't access it until that occurs.

    – charlietfl
    Nov 22 '18 at 0:25













  • The "$(this).on('click', function() {" is getting in your way. This looks like a validation function, but you are binding an event handler which won't fire till the user clicks something. Try removing the binding and see if that helps.

    – Sage
    Nov 22 '18 at 0:26











  • even if i comment out the click function i still get 'undefined' response..

    – RMCS
    Nov 22 '18 at 15:46














0












0








0









This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers




I'm really stuck with getting a value from this function, my guess is that it is because of the functions inside the functions.



(ps. I know I don't have to use quotes when I want to get a BOOL value)



Please help



$(document).ready(function() {    
var text = null;

function textCheck() {
if ($('.window-' + sc).has('input[type="text"]')) {
$(this).find('input[type="text"]').each(function() {
$(this).on('click', function() {
if ($(this).attr('required')) {
var placeholder = $(this).attr('original');

if (!$(this).val() == '') {
$(this).removeClass('is-invalid shake').addClass('is-valid').attr('placeholder', placeholder);
text = 'true';
//return text;
} else {
$(this).addClass('is-invalid shake').attr('placeholder', placeholder + " can't be empty");
text = 'false';
//return text;
};
};

});
});
};
return text;
};

var texxt = textCheck();
console.log(texxt);
});









share|improve this question

















This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers




I'm really stuck with getting a value from this function, my guess is that it is because of the functions inside the functions.



(ps. I know I don't have to use quotes when I want to get a BOOL value)



Please help



$(document).ready(function() {    
var text = null;

function textCheck() {
if ($('.window-' + sc).has('input[type="text"]')) {
$(this).find('input[type="text"]').each(function() {
$(this).on('click', function() {
if ($(this).attr('required')) {
var placeholder = $(this).attr('original');

if (!$(this).val() == '') {
$(this).removeClass('is-invalid shake').addClass('is-valid').attr('placeholder', placeholder);
text = 'true';
//return text;
} else {
$(this).addClass('is-invalid shake').attr('placeholder', placeholder + " can't be empty");
text = 'false';
//return text;
};
};

});
});
};
return text;
};

var texxt = textCheck();
console.log(texxt);
});




This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers








javascript jquery function return






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 2:09









A J

5572721




5572721










asked Nov 22 '18 at 0:19









RMCSRMCS

608




608




marked as duplicate by Quentin javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 0:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Quentin javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 0:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Logic is flawed. The value of text gets assigned after user clicks on an <input>. You can't access it until that occurs.

    – charlietfl
    Nov 22 '18 at 0:25













  • The "$(this).on('click', function() {" is getting in your way. This looks like a validation function, but you are binding an event handler which won't fire till the user clicks something. Try removing the binding and see if that helps.

    – Sage
    Nov 22 '18 at 0:26











  • even if i comment out the click function i still get 'undefined' response..

    – RMCS
    Nov 22 '18 at 15:46














  • 1





    Logic is flawed. The value of text gets assigned after user clicks on an <input>. You can't access it until that occurs.

    – charlietfl
    Nov 22 '18 at 0:25













  • The "$(this).on('click', function() {" is getting in your way. This looks like a validation function, but you are binding an event handler which won't fire till the user clicks something. Try removing the binding and see if that helps.

    – Sage
    Nov 22 '18 at 0:26











  • even if i comment out the click function i still get 'undefined' response..

    – RMCS
    Nov 22 '18 at 15:46








1




1





Logic is flawed. The value of text gets assigned after user clicks on an <input>. You can't access it until that occurs.

– charlietfl
Nov 22 '18 at 0:25







Logic is flawed. The value of text gets assigned after user clicks on an <input>. You can't access it until that occurs.

– charlietfl
Nov 22 '18 at 0:25















The "$(this).on('click', function() {" is getting in your way. This looks like a validation function, but you are binding an event handler which won't fire till the user clicks something. Try removing the binding and see if that helps.

– Sage
Nov 22 '18 at 0:26





The "$(this).on('click', function() {" is getting in your way. This looks like a validation function, but you are binding an event handler which won't fire till the user clicks something. Try removing the binding and see if that helps.

– Sage
Nov 22 '18 at 0:26













even if i comment out the click function i still get 'undefined' response..

– RMCS
Nov 22 '18 at 15:46





even if i comment out the click function i still get 'undefined' response..

– RMCS
Nov 22 '18 at 15:46












1 Answer
1






active

oldest

votes


















1














in you textCheck() function ,the first $(this) stands for window

change this to your element






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    in you textCheck() function ,the first $(this) stands for window

    change this to your element






    share|improve this answer




























      1














      in you textCheck() function ,the first $(this) stands for window

      change this to your element






      share|improve this answer


























        1












        1








        1







        in you textCheck() function ,the first $(this) stands for window

        change this to your element






        share|improve this answer













        in you textCheck() function ,the first $(this) stands for window

        change this to your element







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 0:31









        Abdulsattar AlkhalafAbdulsattar Alkhalaf

        33216




        33216

















            62,hfMMdz,4oU4fSxnVRv,odhd,LVOb1Spd3S2N,Gwvi6GuTs IVj,6RWvDZ92A
            aJti9QX,wkEGf4xTfzsKlMFhO,QPVqGRrhP,s4D6hjzf uD,jKbTIC Hh OzCc77OoO Brz14YP9wY,MVnKC97C7TZUhd,KAQIqLGNYfte4

            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            Guess what letter conforming each word

            Run scheduled task as local user group (not BUILTIN)