Web Analytics Made Easy -
StatCounter JavaScript loops - CodingForum

Announcement

Collapse
No announcement yet.

JavaScript loops

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • JavaScript loops

    Hi all.

    I have hard-coded several images as onMouseOver links but I need to achieve the same result using a loop somehow. That is, rather than as in my p.s. below where I have explicitly coded all the image names and positions, I need to be able to make these references variable depending on where I am within a loop.

    With languages I know I would do something like the following:

    name_str = 'thursday,friday ,saturday,sunday '
    kount = 0
    FOR loop=1 TO 28 STEP 9
    kount = kount + 1
    which = ALLTRIM(STR(kount))
    ** The next line would hold "thursday.png" when loop = 1
    image_name = SUBSTR(name_str,loop,8)+".png"
    ** The next line displays "thursday.png"
    ?&image_name
    ENDFOR

    The & symbol lets me display the contents of the variable.

    Is there a similar way to achieve the same result using JavaScript? What is the equivalent to & for numbered variables created within a JavaScript loop?

    Thanks a lot.

    Russell.

    p.s. The following is the code I have at the moment:

    <a href="Connect.asp" target="list" onMouseOver="hiLite('thursday','thursday_on','Option 1')"
    onMouseOut="hiLite('thursday','thursday_off','')">
    <img name="thursday" style="position:absolute;top:92;left:1;border-style: solid; border-color: black" src="thursday_off.png" border="1" width="117" height="29"></a>

    <a href="Connect.asp" target="list" onMouseOver="hiLite('friday','friday_on','Option 2')"
    onMouseOut="hiLite('friday','friday_off','')">
    <img name="friday" style="position:absolute;top:121;left:1;border-style: solid; border-color: black" src="friday_off.png" border="1" width="117" height="29"></a>

    <a href="Connect.asp" target="list" onMouseOver="hiLite('saturday','saturday_on','Option 3')"
    onMouseOut="hiLite('saturday','saturday_off','')">
    <img name="saturday" style="position:absolute;top:150;left:1;border-style: solid; border-color: black" src="saturday_off.png" border="1" width="117" height="29"></a>

    <a href="Connect.asp" target="list" onMouseOver="hiLite('sunday','sunday_on','Option 4')"
    onMouseOut="hiLite('sunday','sunday_off','')">
    <img name="sunday" style="position:absolute;top:179;left:1;border-style: solid; border-color: black" src="sunday_off.png" border="1" width="117" height="29"></a>

  • #2
    Could you be more specific - exactly what behavior are you trying to program?

    Comment


    • #3
      Variable loops

      Thanks for your email adios.

      I would like to produce images on the screen (for example, Day 1, Day 2, Day 3 ... buttons) which use onMouseOver and are used as links to an asp page.

      The problem is I don't know how many buttons there will be beforehand. I'm assuming, therefore, that I need to use a loop.

      So instead of hard coding:

      <img src="Day1.png" ...>
      <img src="Day2.png" ...>
      etc

      I would like to know the syntax in JavaScript (if indeed I need scripting) to create these references within a loop.

      With Visual FoxPro, with which I usually program, I normally increment a counter and use "&" to distinguish between elements 1, 2, 3 ....

      For example:

      FOR loop=1 TO 3
      which_button = STR(loop)
      image&which_button = "Day"+which_button+".png"
      ENDFOR

      would create variables image1, image2, image3 containing the text "Day1.png", "Day2.png", "Day3.png".

      How would I do this in JavaScript?

      Thanks.

      Russell.

      Comment

      Working...
      X