Click to See Complete Forum and Search --> : Finding and calling up functions.


neil9999
12-18-2003, 12:38 PM
Hi,

I have a function resize() called up several times on the page but with different information in the brackets. I need to find the first time the function is called up on the page, and run the function according to the information in the brackets. There should be a five second gap, then it finds the second time the function is called up etc.

Eg.

If my code was:

<body>

<button onclick="resize('cat','2')">Cat</button>
<button onclick="resize('dog','1')">Dog</button>
<button onclick="resize('rhino','7')">Rhino</button>
</body>

Then when my page is loaded, resize('cat','2') would be called up. After five seconds resize('dog','1') would be run and after another five seconds resize('rhino','7') would be run. After another five seconds it would go back to the start and run resize('cat','2') again.

I hope you can help,

Thanks,

Neil

TheBearMay
12-18-2003, 05:30 PM
Not knowing what your parameters are doing, try this:


var nameArr = ["cat", "dog", "rhino"....
var numArr=[2,1,7...
var nameInx=0;

function setName(){
resize(nameArr[nameInx], numArr[nameInx]);
nameInx++;
if (nameInx > nameArr.length-1) nameInx=0;
setTimeout(setName(), 5000);
...

neil9999
12-19-2003, 02:25 AM
Thanks for your help.

I've had to attatch the code, as this forum keeps changing my code into smilies!!!

Anyway, if you find this part of the code:

var idpicArr = ["cam", "cam2"];
var srcsArr=["chameleon1.bmp","chameleon2.bmp"];
var captArr=["Chameleon","Another chameleon"];
var idpicInx=0;

you'll see that you have to specify all the different possiblilities of what could be in the brackets in the actual script. I want the script to find these possibilities.

This should give you the right idea:

var findRes=document.scanForHTML(resize(a???,b???,c???));
var idpicArr=[findRes.a???];
var srcsArr=[findRes.b???];
var captArr=[findRes.c???];

//rest of code here.

I know this code wouldn't actually work, it's just to show you the logic of it.

Thanks again,

Neil

neil9999
12-20-2003, 03:13 AM
So basiccly the script would scan the whole page for callups of the resize() function. If you put in another callup of the resize() function you shouldn't have to change the script, as the script would detect the function.

Thanks,

Neil

neil9999
12-25-2003, 09:03 AM
All I want to do is scan the HTML of the page for resize(anytexthere) and put whatever it finds into an array.

So if my page was this:

<button onclick="resize(cat)">Cat</button>
<button onclick="resize(dog)">Dog</button>

the two items in the array would be "cat" and "dog".

Thanks,

Neil