By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,107 Members | 931 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,107 IT Pros & Developers. It's quick & easy.

Dynamically pass value in anchor

P: 7
Hi everyone,

I'm using anchor within the for loop which means the number of anchors(links) dynamically varies.
Within the anchor i'm calling one javascript function and passing the dynamic value (select ) in that. The problem is even i click any link only last value i.e..select value at i = j is passing because the looping will happen during loading the page itself...so how can i pass exact values? Do i need to set any ID for the tag?If so how? Can Anybody please help?

for(i = 1; i < = j; i++)
{
select = document.forms['MessageNew'].userId.options[i].value;

selection[i] = '<a onclick="javascript:assignValue(select);"><font size="2">'+selection1+'</font></a><br>'

}
Apr 26 '07 #1
Share this Question
Share on Google+
1 Reply

P: 7
Hi Everyone..

Please observe the below code

function fun(){
for(i = 1; i < = j; i++){
select = document.forms['MessageNew'].userId.options[i].value;
selection[i] = '<a href="javascript:assignValue(select);"> + select + </a>';
}
}

Assume j = 10, looping will happen for 10 times and 10 links will appear.
Let us assume value of 'select' is 'ABCD' when i = 1 and at i = 10, value of select will be 'XYZ' . Observe that in href we are calling one javascript function assignValue(select) and passing select in that. This javascript will be called when i click the link, even i click link number 1, XYZ will be passed to the assignValue() since looping is completed. But i need ABCD to be passed when i click link 1 and the respective values should be passed for link2,link3...,link10.
I hope you got my prob..Please help me how can i approach the solution.
Thanks a lot...
May 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.