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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable value as parameter

Status
Not open for further replies.

Ziga

Programmer
Jun 9, 2010
2
Hi, I'm sort of new to javascript and I'm having a problem

this is my code

for(i=1;i<=68;i++){
content+="<p onclick='myf(i)'>Some text</p>";
}

What I'm trying to do is that when you click on this text it would send the index of it to function 'myf'. But in the code as I have it above it would send 68 for all paragraphs. How could I put the value of i in the parameter instead of 'i'? Like '1' and '2' and so on.

And this isn't the actual code, it's just simplified. I have an array and it would send array.

Thanks for any help.
 
>content+="<p onclick='myf(i)'>Some text</p>";
[tt]content+="<p onclick='myf([red]"+i+"[/red])'>Some text</p>";[/tt]
 
Yes that solved my problem. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top