File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Passing values dynamically in Anchor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Passing values dynamically in Anchor" Watch "Passing values dynamically in Anchor" New topic

Passing values dynamically in Anchor

Praveen Kumar Anekalmath

Joined: Feb 26, 2007
Posts: 18
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 value at i = j is passing because the looping will happen during loading the page how can i pass exact values? Do i need to set any ID for the tag?If so how? Can Anybody please help?
I Have not used anchor tag since it is not allowed in in posting the message
for(i = 1; i < = j; i++)
select = document.forms['MessageNew'].userId.options[i].value;

selection[i] = 'a href="javascript:assignValue(select);"+selection1+ /a


Omer Haderi
Ranch Hand

Joined: Sep 27, 2006
Posts: 42
Dude this is Java forum for the Sun Certification Not a javascript forum, there are plenty of javascript forums !
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
From the SCJP forum with love...

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 406

I assume that the single quote on the end is only missing in your code snippet above because you accidentally deleted it along with the last >

You are building an array containing anchors. What is selection1?
[ April 26, 2007: Message edited by: Roger F. Gay ]

Correlation does not prove causality.
Praveen Kumar Anekalmath

Joined: Feb 26, 2007
Posts: 18
Thanks for your kind reply Roger.

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

It is not selection1, it is select which takes the value runtime.
I missed to add single quote at last..but it is there in the code.
I think my question is not clarified for you.
I am calling function fun(), for loop executes and number of links will appear depending on the value of j.What i am trying to do is, i need to pass 'select' value for each links when i click the link but only final select value i.e for i=j, is if i click any link only last select value(i=j) will go.
i need 'select' values for all the valuse of i.
Do i need to give id to anchor ? how to approach this?

Thanks a lot...
wood burning stoves
subject: Passing values dynamically in Anchor