Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm calling a function like this:
$('.qa-nav-main-ask a').click(showAskForm);
Show showAskForm is this (simplified):
function showAskForm(){
return true;
}
I want to catch the response from showAskForm and save it to a variable, I tried
askFormShowing = $('.qa-nav-main-ask a').click(showAskForm);
without success.
function showAskForm(){
return true;
}
var askFormShowing;
$('.qa-nav-main-ask a').click(function(){askFormShowing = showAskForm();});
Try the above
return is a reserved word and cannot be used as a JavaScript identifier. So, use like this:
$('.qa-nav-main-ask a').click(showAskForm);
function showAskForm(){
myvar = true;
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The page just echoes the user input using GET. I have no idea on what concept to apply to detect if the user has alerted something
The easiest approach would probably be to replace the alert method with your own.
const log = [];
alert = function(alert) {
return (value) => {
log.push(value);
alert(value);
};
}(alert);
alert("Hello!");
console.log(log);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Hello I'm trying to make DRY code (not repeat code) from the a secondFunction that inherits NEARLY all the content from a firstFunction.
This would be the example of what I want but it's not DRY:
function firstFunction(){
this.arrayObjectsToElastic = ["hello1", "hello2"]
this.anothervariable1= "anothervariable1"
this.anothervariable2= "anothervariable2"
this.targetVariableToRemove = "something"
return [this.arrayObjectsToElastic]
}
function secondFunction(){
this.arrayObjectsToElastic = ["hello1", "hello2"]
this.anothervariable1= "anothervariable1"
this.anothervariable2= "anothervariable2"
return [this.arrayObjectsToElastic]
}
Therefore, I don't want to "inherit" in the secondFunction the targetVariableToRemove from the firstFunction because if so it'll crash in some other processes I'm running.
Maybe you can do something like:
function secondFunction(){
return firstFunction().concat(["newContent"]);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Question is being edited. Sorry for changes. Please don't provide answers at the moment :)
If I declare an object in javascript:
var MyObject = {
function myFunction() {
console.log('hi!');
}
}
Why do I get errors?
Wouldn't it rather be:
var MyObject = {
myFunction : function(){
console.log('hi!');
}
}
How to call the method:
MyObject.myFunction()
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have this code:
replaceAny('this','that',string);
if(val!="")
the replaceAny function looks like this:
function replaceAny(first,second,ele) {
var val = ele.replace(first,second);
alert(val);
return val;
}
But then after running the replaceAny function (and the alert shows the right value, the if condition tells me that the variable val is not set, why?!
You are not using the return value from the function correctly. This is something like what you want
function replaceAny(first,second,ele) {
return ele.replace(first,second);
}
var val = replaceAny('this','that',string);
if(val!=""){
//something, something darkside
}
I think you are not assigning the value returned by your function to your variable val.
Try like this
val = replaceAny('this','that',string);
if(val!="")
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
if( hasWhiteSpace($(this).find(".nospace:input").val()) ){
$(this).find(".nospace:input").filter(function() {
return hasWhiteSpace(this.value) == true;
}).addClass("blank");
setError(".motd_register_company","There must be no space in between.");
return false;
}
There is something wrong about my code above, and the code only validate the first input, while the others not, how could I validate all the "nospace" class that I have in my form?
can you guys trim my code if there is something wrong.
Are you trying to recursively search elements for a particular classname? If so:
$('input.class_name').each(function() {
// Do you stuff to this input element
});
jQuery.each("input.nospace", function(i, el){
var self = $(el);
if(hasWhiteSpace(self.val()) self.addClass("blank");
});