Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: looping - help

  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    looping - help

    hi to all... good day to u all...

    i have a noob question

    i followed this instruction
    Code:
    for (count=1; count<11; count++) {
         javascript code here
    }
    at the bottom of my page i did this
    Code:
    <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
    Code:
    <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...

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    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
    Code:
    var followTrigger = []
    ...
       followTrigger[counter] = ....
    Last edited by devnull69; 09-28-2011 at 02:53 PM.

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    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
    Code:
    var followTrigger = [];
    for (counter=1; counter<11; counter++) {
    	followTrigger[counter] = new Spry.Widget.Tooltip('following'+counter+'a', '#followMe'+counter+'a', {followMouse: true});
    }

  • #5
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Code:
    <script src="SpryAssets/SpryTooltip.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryTooltip.css" rel="stylesheet" type="text/css">
    Spry.Widget here
    Code:
            <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
    Code:
    <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.
    Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •