get value from function inside function jquery [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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);
});
javascript jquery function return
marked as duplicate by Quentin
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.
add a comment |
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);
});
javascript jquery function return
marked as duplicate by Quentin
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 oftext
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
add a comment |
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);
});
javascript jquery function return
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
javascript jquery function return
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
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
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 oftext
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
add a comment |
1
Logic is flawed. The value oftext
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
add a comment |
1 Answer
1
active
oldest
votes
in you textCheck() function ,the first $(this) stands for window
change this to your element
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
in you textCheck() function ,the first $(this) stands for window
change this to your element
add a comment |
in you textCheck() function ,the first $(this) stands for window
change this to your element
add a comment |
in you textCheck() function ,the first $(this) stands for window
change this to your element
in you textCheck() function ,the first $(this) stands for window
change this to your element
answered Nov 22 '18 at 0:31
Abdulsattar AlkhalafAbdulsattar Alkhalaf
33216
33216
add a comment |
add a comment |
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