...

View Full Version : Activating functions from other functions?



mjcox2000
03-16-2012, 01:49 AM
Is there a way to activate a function from another function? It has to be in the script tag, it can't be in the HTML section. Can I use something similar to this following code? If not, can anyone give me some help? I have tried to do it various ways, and have looked it up a few times, but to no avail. Can I use something similar to this following code? If not, can anyone give me some help?

if (condition)
{activate functionname();}

Any help I can get would be appreciated. Thanks a lot to anyone who can help.

DanInMa
03-16-2012, 01:57 AM
if (condition){
functionname();
}

mjcox2000
03-16-2012, 02:04 AM
Does it work like this?

if (condition)
{
alert("Condition is true");
functionname();
}

If not, I can change my code to something that works the same way, but either way, thanks a lot.

felgall
03-16-2012, 02:09 AM
That's how you do it if you want it to run straight away. If you want it to run as a response to an event then you'd attach it to the element in the HTML and the appropriate event handler using


document.getElementById('id_of_tag').oneventname = functionname;

for example


document.getElementById('myid').onclick= dosomething;

(or if you want to make sure it doesn't clash with other processing attached to the same event then use an event listener instead)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum