HyperLink text property undefined

A

avanti

HI,
I have a HyperLink in my code. It has a OnClick function defined. I am
trying to access the text property of the HyperLink in my JavaScript
function.

<CoreCtrl:Controls.WebControls.HyperLink id="securityCodeLink" text="My

Text" OnClick="ShowText(this);" Href="#" CssClass="textSmall"
runat="server" />

function ShowText(obj)
{
alert(obj.text);
}

I also tried getting a var for the hyperlink with its id and showing
its text. It says 'undefined' instead of 'My Text'. Am I doing
something wrong?

Thanks,
Avanti
 
C

Chad Burggraf

avanti said:
function ShowText(obj)
{
alert(obj.text);
}

I also tried getting a var for the hyperlink with its id and showing
its text. It says 'undefined' instead of 'My Text'. Am I doing
something wrong?

There is no default property called "text" for anchor elements. You
should use innerHTML as follows:

function ShowText(obj) {
alert(obj.innerHTML);
}
 
J

Jim

Avanti,
You can determine the text attribute value in this manner:
<a href="#"
text="sometext should go here"
onClick="alert(this.getAttribute('text'))"Show the Text Attribute Value
</a>

Hope that helps,

Jim
 
A

avanti

Thanks guys for the quick reply. It worked!
Avanti,
You can determine the text attribute value in this manner:
<a href="#"
text="sometext should go here"
onClick="alert(this.getAttribute('text'))"
Show the Text Attribute Value
</a>

Hope that helps,

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top