undefined value in Alert window

P

Phil

Hi,

The Alert window appears but the value is "undefined".
I tried two ways
What don't i see here?
Thanks
Phil

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title>Untitled Page</title></head>
<body> <form id="form1" runat="server">
<asp:Label ID="label1" runat="server" text="ok" Font-Bold="True"
forecolor="lightsteelblue"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClientClick="test()" />

<script language="javascript" type="text/javascript">
function test()
{
var x = document.getElementById("label1").text;
//var x = document.getElementById('<%=label1.ClientID%>').text;
doesn't work
alert(x)
}
</script> </form> </body></html>
 
T

Teemu Keiski

Label (rendered as <SPAN> at client) does not have text property at
client-side dom. What if you write for example:

var x = document.getElementById("label1").innerText;
 
E

Evertjan.

Phil wrote on 08 mrt 2007 in microsoft.public.scripting.jscript:
Hi,

The Alert window appears but the value is "undefined".
I tried two ways
What don't i see here?
Thanks
Phil

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title>Untitled Page</title></head>
<body> <form id="form1" runat="server">
<asp:Label ID="label1" runat="server" text="ok" Font-Bold="True"
forecolor="lightsteelblue"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClientClick="test()" />

<script language="javascript" type="text/javascript">
function test()
{
var x = document.getElementById("label1").text;
//var x = document.getElementById('<%=label1.ClientID%>').text;
doesn't work
alert(x)
}
</script> </form> </body></html>

..text is not a DOM extention, perhaps .value.

However perhaps better ask in a dotnet group.

<microsoft.public.dotnet.framework.aspnet>
 
A

Anthony Jones

Phil said:
Hi,

The Alert window appears but the value is "undefined".
I tried two ways
What don't i see here?
Thanks
Phil

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title>Untitled Page</title></head>
<body> <form id="form1" runat="server">
<asp:Label ID="label1" runat="server" text="ok" Font-Bold="True"
forecolor="lightsteelblue"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClientClick="test()" />

<script language="javascript" type="text/javascript">
function test()
{
var x = document.getElementById("label1").text;
//var x = document.getElementById('<%=label1.ClientID%>').text;
doesn't work
alert(x)
}
</script> </form> </body></html>

I'm not up on ASP.NET but the first thing I would check is whether the
ID="label1" actually ends up on an element in the output HTML. Use view
source in your browser and do a text search.

My guess is that it isn't and that you need to repost to
microsoft.public.dotnet.framework.aspnet to get someone to explain.
 
P

Phil

Thanks

Anthony Jones said:
I'm not up on ASP.NET but the first thing I would check is whether the
ID="label1" actually ends up on an element in the output HTML. Use view
source in your browser and do a text search.

My guess is that it isn't and that you need to repost to
microsoft.public.dotnet.framework.aspnet to get someone to explain.
 

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,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top