JavaScript not starting function - javascript

I have search for some sort of way to do this, but i can't make it work. It may seem simple but i don't know much about javascript so I have found very little information on the problem and I don't know were is the error at so i'll just briefly explain what it's supposed to do. First here is my code:
function showI(a){
$("#show").fadeIn();
$("#show .load").fadeIn();
$("#show").load("ajax/showi.php?id="+a,$("#show .load").fadeOut("fast"))
}
$('.List-item').on('click touchstart',function(){
var id=$(this).attr("id").split("list-").join();
showI(id);
})
So there's like a button with the class list-item which when click should open a new window with the showI function, but it doesn't(I used before the attribute onClick, but it didn't work on mobile so I changed it to .on(click touchstart))
Any help would be appreciate. (Don't know if this is replicated because i can't find a word to describe the problem)

This line:
$("#show").load("ajax/showi.php?id="+a,$("#show .load").fadeOut("fast"))
calls $("#show .load").fadeOut("fast") and then passes its return value into load as a second argument, exactly the way foo(bar()) calls bar and then passes its return value into foo.
If you're looking for a completion callback, you need to wrap that in a function:
$("#show").load("ajax/showi.php?id="+a, function() {
$("#show .load").fadeOut("fast");
});

Related

Pass Component Name as Argument and then attach method (not working?)

Maybe I'm not using the right terms/names for my searches but I have not been able to find anything on this topic. I would have thought this would be an easy thing to find. What I'm doing is passing a component name to a function and then trying to use the component's name by attaching a method to it. I have confirmed (via Dev Tools) that the name is correctly being passed but when I use the variable and attach the method the specific request does not work. If I 'hard-code' the exact component name to the method it works perfectly. This makes me think the (various) ways I've been trying to attach the method to the variable name is incorrect (see various attempts below). Can you offer some direction here? Thank you.
Passing to Function ...
const grid_name = "grid_GroupA";
console.log(grid_name); // Shows grid_GroupA
msg_max(newItem, grid_name);
Function (only listing relevant parts)
function msg_max(newItem, grid_target) {
console.log(grid_target); // Shows grid_GroupA
// grid_GroupA.data.add(newItem); // This works ...
// grid_target.data.add(newItem); // This does not work
// (grid_target).data.add(newItem); // This does not work
// [grid_target].data.add(newItem); // This does not work
// grid_target + '.data.add(newItem)'; // This does not work
Thank you ...
Edit ...
In my attempt to provide detail I hope I haven't confused the issue.
In essence, my question is if I can type this exact string
grid_GroupA.data.add(newItem);
and it works for my function, how can I place a variable with the exact string "grid_GroupA" in front of ".data.add(newItem);" and have it seen the same as the line of code that works? Maybe my lack of knowledge here is getting in the way but isn't the line of code that works just a string that is then used to 'find' the object? So, if that assumption is correct, how do I create that same string with the variable? If my assumption is wrong I am a willing learner so I will be all ears. Thank you.
I do not see how grid_target is an object. You are passing grid_name(which is a string) to the function, so grid_target will have no data property, because string doesn't have such a member.
P.S. snake_case is bad option for JavaScript, consider using cameCase instead

Can't get it to work: Use value from one javascript function in another function

I'm practising with several javascript functions, which all work fine separately. But if I try to get a value from one function into another function I can't get it to work.
I've read multiple threads overhere (and elsewhere) and have been trying with several options like 'return', 'callback', console.log, merging the functions, etc.
No result for me... Could you help me?
My fiddle is:
Fiddle
I would like to use the value of variable 'direction' inside function geo() in another function: processSVData(). In processSVData I would use the direction 2 times.
Your code doesn't work because the function which accesses the direction variable accesses it before it is set. I've changed script ordering here and it works fine now: http://jsfiddle.net/bz2g5ong/7/
I cannot read the code but, as a general idea:
function iNeedData(preciousData) {
console.log(preciousData);
}
function iSendData() {
iNeedData("Wow, data!");
}
iSendData();

jointJS javascript logic circuit example

I am trying to understand how jointJS works, specifically this example logic circuit simulation
There are few parts which I am not quite sure what is happening.
_.invoke(graph.getLinks(), 'set', 'signal', 0);
Looking at the invoke function, 'set' and 'signal' should be the methodNames, but how can we use two methods at the same time?
graph.on('change:signal', function(wire, signal)
Translating this would be.. when the signal is changed, function(wire,signal) is run. As i'm quite new with Javascript, I don't know what is being passed (wire, signal) into this function and how it is obtained?
Thanks in advance
For your first question _.invoke(graph.getLinks(), 'set', 'signal', 0);
It's using the underscore.js function of invoke. It will take a list (your graph.getLinks() list) and invoke a method on each item in that list. The arguments are taken after the function. So in this case, you're getting all of the links on the graph, and then setting the signal to 0 for each one of them.
For your second command graph.on('change:signal', function(wire, signal)
From what i've worked with on joint, this is a backbone.js event. Where the function passes in for the change event. http://backbonejs.org/#Events-catalog Usually it's one of two items there in that list. The change event, or the change:attribute event. So this looks like a change:signal which is an attribute, so it's probably (model, view, options) is what it's passing in. If you're really curious of the data available, use chrome and set a breakpoint to inspect the variables being passed in.
Hope that helps.
For reference :
http://underscorejs.org/
http://backbonejs.org/

Call an javascript function from actionscript script

I am trying to build a button that will active specific Javascript function.
I tried:
getURL("javascript:functionName()");
but its seems like a bad idea (plus it doesn't work)..
or
import flash.external.ExternalInterface;
function call_javascript(evt:MouseEvent):void {
ExternalInterface.call("functioName()");
}
btn.addEventListener(MouseEvent.MOUSE_UP, call_javascript);
none of this working for me..
First of all, this is a duplicate. The question has been asked about 10 times before. But, here is an answer for you: ExternalInterface.call("jsFunctionName", argument, argument, ...);. It is very possible. Click here for more details.
Your problem is that you are calling it wrong. The 1st param should be the function name without the brackets: ExternalInterface.call("funcionName");
Also note that you will have to have allowScriptAccess set to a value that will actually allow you to call the function (in your example you have sameDomain, which is OK).

window.setInterval - is it possible to have more than one? how?

I have created a slideshow widget, using jQuery.UI widgets that works with window.setInterval.
I am trying to have more than one slideshow in the same page and i get the following results:
If I try invoking the same widget for both of my divs with images:
$('#div1').slideshow();
$('#div2').slideshow();
none of them work;
I have cloned the definition of my widget and named it slideshowsmall
$('#div1').slideshow();
$('#div2').slideshowsmall();
and only the second one works.
my widget code is in this pastebin, but i really think the problem, at least in the second try, has to do with setInterval
Thanks
Having multiple setInterval() by itself cannot be causing problems. It is more likely to have something to do with the code it's executing (and your widget code being non-english makes it very hard to analize and comprehend).
setInterval() returns and integer ID of the "interval", so that you can later clearInterval(...) by passing this ID. This scenario was implemented exactly for multi-interval uses. More details on MDC
As per your widget code when setInterval calls the ChangeLeft/Right.. method the slideshowdiv variable always points to the last element on which slideShow is called. the reason for this is the way you are invoking change methods which is not adviceable.
Please use the below code to call your change method it should solve your problem. You will notice I am passing the slideshowdiv object to change methods.
this.options.timer = window.setInterval(function () {
ChangeImageLeft(velocidade, slideshowdiv);
}, intervalo);
Let me know if you need more info.

Categories

Resources