PDA

View Full Version : how to capture the hyperlink text property in javascript


shoba2b
02-05-2008, 05:14 AM
Hello everyone

In my application, i have to display the employee information and the employee name(with first name and last name) as hyperlink....n when i click the hyperlink i should get the information of that particular employee as in the edit page..............what all i need is, i want to capture the data which is the hyperlink and through that i have to get the data of that hyperlink from database...through Javascript n java
help me out!!!!!!

thnku in advance
shoba

RexxCrow
02-05-2008, 05:24 AM
I am not sure this is really basic but something like this?


To read from the link:
variablename=document.getElementById('myAnchorId').innerHTML='name'

To set the link:
document.getElementById('myAnchorId').href='name'

Ultragames
02-05-2008, 08:17 AM
The best way would be to place that information into the link, like so:

<a href="edit_page.html?user=jonny">Jonny Smith</a>

However, if you are lookign for the Javascript anyways, you do this:

<a href="edit_page.html" onclick="alert('The name is: '+this.firstChild.data);">Jonny Smith</a>

It is the this.firstChild.data that you want. If you were using an ID to get it, then it would look like document.getElementById('MyLinksID').firstChild.data

rnd me
02-05-2008, 05:46 PM
".data" doesn't do anything for me in ffrefox.

".innerHTML" works for me in FF, IE, safari, and opera (is there anything else?)

shoba2b
02-06-2008, 06:10 AM
hi

this is the view part, i have displayed the client name as a hyperlink and when i click the link it goes to the controller where i have defined the edit page.(where i should b navigated to)

<a href="controller?EVENT_NAME=EDITCLIENT_LINK "><%=cname%></a>

the problem is, im unable to capture the data "cname" which i have set as a hyperlink ..............where when i click the option it should capture that data and go to the controller part


so wat should i write to capture the data , i mean the "cname"

glenngv
02-06-2008, 07:11 PM
<a href="controller?EVENT_NAME=EDITCLIENT_LINK&cname=<%=URLEncoder.encode(cname)%>"><%=cname%></a>