Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hardcoding variables from a FOR loop

Status
Not open for further replies.

cesarcesar

Programmer
Mar 5, 2003
30
i have a FOR loop that duplicates the same image across the screen. on each of these images i want an onClick event that sends a variable to a function that pertaines to the spacific image i've clicked.

my problem is that im trying to use the variable used in the FOR loop as my variablwe i want to pass. im not sure if this is correct and i hope i have explained it okay. the JS is below with a few other comments within it. thanks for the help.

<tr>
<SCRIPT LANGUAGE=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>



for (m=1; m<= 10; m++) {

document.write(&quot;<td>&quot;);

document.write(&quot;<a href='#' onClick='alert(m);'>&quot;);
// using alert() for quick checking. need (m) to always be 1 on the first pic and 2 on the second and so one. these nubers are going to be added with a &quot;.jpg&quot;.

document.write(&quot;<img src = 'preview.gif' border='0''>&quot;);
document.write(&quot;</td>&quot;);

}

</SCRIPT>
</tr>

if you feel like chatting me through it, try Windows Messenger - tickers99@hotmail.com
 
I'm slightly confused, but if you always need m to be 1 for one image and 2 for another then I suggest creating three seperate var's
var counter // for loop or the loop will not loop as you never increment the value of m
so counter = counter + 1 for iteration

var m1 = 1
var m2 = 2

if (something then)
write m1
else
write m2

again I'm slightly confused but if you need something to be constant in the loop you're going to go no where trying to use that value of the count of interations in the loop

hope that helps a bit _________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top