...

View Full Version : looping - help



phoenixtaz
09-28-2011, 12:49 PM
hi to all... good day to u all... :)

i have a noob question

i followed this instruction


for (count=1; count<11; count++) {
javascript code here
}

at the bottom of my page i did this


<script type="text/javascript">
for (counter=1; counter<11; counter++) {
var followTrigger+counter+a = new Spry.Widget.Tooltip('following'+counter+'a', '#followMe'+counter+'a', {followMouse: true});
}
</script>

what im trying to do is to make multiple of this


<script type="text/javascript">
var followTrigger1a = new Spry.Widget.Tooltip('following1a', '#followMe1a', {followMouse: true});
var followTrigger2a = new Spry.Widget.Tooltip('following2a', '#followMe2a', {followMouse: true});
var followTrigger3a = new Spry.Widget.Tooltip('following3a', '#followMe3a', {followMouse: true});
var followTrigger4a = new Spry.Widget.Tooltip('following4a', '#followMe4a', {followMouse: true});
var followTrigger5a = new Spry.Widget.Tooltip('following5a', '#followMe5a', {followMouse: true});
var followTrigger6a = new Spry.Widget.Tooltip('following6a', '#followMe6a', {followMouse: true});
var followTrigger7a = new Spry.Widget.Tooltip('following7a', '#followMe7a', {followMouse: true});
var followTrigger8a = new Spry.Widget.Tooltip('following8a', '#followMe8a', {followMouse: true});
var followTrigger9a = new Spry.Widget.Tooltip('following9a', '#followMe9a', {followMouse: true});
var followTrigger10a = new Spry.Widget.Tooltip('following10a', '#followMe10a', {followMouse: true});
</script>

i dont know why it wont work... any help pls...

devnull69
09-28-2011, 02:30 PM
To create a list of variables with similar content you cannot generate variable names like this. You will have to use a different approach, maybe arrays


var followTrigger = []
...
followTrigger[counter] = ....

phoenixtaz
09-28-2011, 08:33 PM
hi devnull69, good day to u. :)

Pls bare with me, im really a noob, with ur given example, how can I apply it to my code?

devnull69
09-28-2011, 10:53 PM
It depends on what you need all those variables for. You create them and that's it. You are not showing what you do with those variables afterwards.

But to give an equivalent example to your suggestion


var followTrigger = [];
for (counter=1; counter<11; counter++) {
followTrigger[counter] = new Spry.Widget.Tooltip('following'+counter+'a', '#followMe'+counter+'a', {followMouse: true});
}

phoenixtaz
09-29-2011, 06:25 AM
hi devnull69, good day to u again.

i used dw cs3, using sprywidget

base on dw, a file was inserted Sprytooltip.css and sprytooltip.js


<script src="SpryAssets/SpryTooltip.js" type="text/javascript"></script>
<link href="SpryAssets/SpryTooltip.css" rel="stylesheet" type="text/css">


Spry.Widget here


<div id="followMe1a">picture here</div>
<div id=""following1a"" class=""tooltipContent"">picture info here</div>

and so on......


and at the bottom of my page in the insctruction of dw tutorial
this should be there


<script type="text/javascript">
var followTrigger1a = new Spry.Widget.Tooltip('following1a', '#followMe1a', {followMouse: true});
var followTrigger2a = new Spry.Widget.Tooltip('following2a', '#followMe2a', {followMouse: true});
var followTrigger3a = new Spry.Widget.Tooltip('following3a', '#followMe3a', {followMouse: true});
var followTrigger4a = new Spry.Widget.Tooltip('following4a', '#followMe4a', {followMouse: true});
var followTrigger5a = new Spry.Widget.Tooltip('following5a', '#followMe5a', {followMouse: true});
var followTrigger6a = new Spry.Widget.Tooltip('following6a', '#followMe6a', {followMouse: true});
var followTrigger7a = new Spry.Widget.Tooltip('following7a', '#followMe7a', {followMouse: true});
var followTrigger8a = new Spry.Widget.Tooltip('following8a', '#followMe8a', {followMouse: true});
var followTrigger9a = new Spry.Widget.Tooltip('following9a', '#followMe9a', {followMouse: true});
var followTrigger10a = new Spry.Widget.Tooltip('following10a', '#followMe10a', {followMouse: true});
</script>


and i have multiple spry widget, i was thinking, intead of typing multiple variables, maybe i can create something like what u did.


var followTrigger = [];
for (counter=1; counter<11; counter++) {
followTrigger[counter] = new Spry.Widget.Tooltip('following'+counter+'a', '#followMe'+counter+'a', {followMouse: true});
}


apparently, the above code is not working, how come the long version is working but not the short version? any other suggestions?

appreciate ur help very much, ty.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum