Getting value from asp:label into javascript input value

D

Dwizz

Hello,
I really hope that someone can help me resolve my problem, I've been
working on it for the past few days, to no avail.

I have an asp:label which gets its value from the database, but what
I'm trying to do is to get that value (from the asp:label) and place it
inside the javascript input value.

I can post sample code if required.

TIA

D
 
D

Dag Sunde

Dwizz said:
Hello,
I really hope that someone can help me resolve my problem, I've been
working on it for the past few days, to no avail.

I have an asp:label which gets its value from the database, but what
I'm trying to do is to get that value (from the asp:label) and place it
inside the javascript input value.

give the <label> an id, and use getElementById(...)

....
var lbl = document.getElementById("labelId");
alert(lbl.value);
....
 
D

Dwizz

Thanks for the quick responce Dag,

so just to clarify,

My ASP:Label is as follows
<asp:Label id="Label2" font-names="Arial" font-size="X-Small"
runat="server">Label</asp:Label>

my Javascript input should be as follows;
<script>
var lbl = document.getElementById(Label2);
alert(lbl.value);
</script>

<input id="Label2" readonly="readonly" type="text" value=""
name="unitprice[]" />
 
A

ASM

Dwizz said:
Thanks for the quick responce Dag,

so just to clarify,

My ASP:Label is as follows
<asp:Label id="Label2" font-names="Arial" font-size="X-Small"
runat="server">Label</asp:Label>

my Javascript input should be as follows;
<script>
var lbl = document.getElementById(Label2);
alert(lbl.value);
</script>

<input id="Label2" readonly="readonly" type="text" value=""
name="unitprice[]" />

I know aything about asp, but something like that ?

<input id="Label2" readonly="readonly" type="text"
name="unitprice[]"
value="<% execute "response.write Label" %>" />

where *Label* would be your asp Label value
 
D

Dwizz

Thanks for the reply ASM,
but when I use the code below I get a compiler error saying execute is
not declared
 
D

Dwizz

Thanks for the reply ASM,
but when I use the following code I get a compiler error, saying
execute is not declared


<input id="Label2" readonly="readonly" type="text"
name="unitprice[]"
value="<% execute "response.write Label" %>" />
 
A

ASM

Dwizz said:
I get a compiler error, saying
execute is not declared

As said : I know anything about asp
And you ?

Found this code in a site given by Google
value="<% execute "response.write Label" %>" />

execute :
http://support.microsoft.com/kb/q224363/

I said *something like that*
In other words,
You have via asp :
- to declare a variable i.e : 'Label'
- and to give to it the value you want to display
then (I hope this time it will be corect ?) :

<input id="Label2" readonly="readonly" type="text"
name="unitprice[]"
value="<% =Label" %>" />
 
D

Dag Sunde

Dwizz said:
Thanks for the quick responce Dag,

so just to clarify,

My ASP:Label is as follows
<asp:Label id="Label2" font-names="Arial" font-size="X-Small"
runat="server">Label</asp:Label>

my Javascript input should be as follows;
<script>
var lbl = document.getElementById(Label2);
alert(lbl.value);
</script>

<input id="Label2" readonly="readonly" type="text" value=""
name="unitprice[]" />

Almost... You must quote the id:
var lbl = document.getElementById("Label2");

But maybe I'm wrong here... asp:xxx is dotnet, isn't it?

I thought you asked how to get the content of a html <label> tag.
In the sample above, you're refering to <asp:label>, and I'll have to admit
I don't have a clue what that is.

Anothewr thing is that an id attribute must be unique within the page
(You repeat it in the <input> tag...
 
R

Randy Webb

Dwizz said the following on 8/5/2005 6:07 AM:
Hello,
I really hope that someone can help me resolve my problem, I've been
working on it for the past few days, to no avail.

I have an asp:label which gets its value from the database, but what
I'm trying to do is to get that value (from the asp:label) and place it
inside the javascript input value.

Then have the ASP put it into a javascript variable.
 
R

RobG

Dwizz said:
Thanks for the quick responce Dag,

so just to clarify,

My ASP:Label is as follows
<asp:Label id="Label2" font-names="Arial" font-size="X-Small"
runat="server">Label</asp:Label>

my Javascript input should be as follows;
<script>

The type attribute is required (but is not likely to be the source of
your problem):

var lbl = document.getElementById(Label2);

Add quotes around the id as per Dag's advice:

var lbl = document.getElementById("Label2");
alert(lbl.value);
</script>

<input id="Label2" readonly="readonly" type="text" value=""
name="unitprice[]" />

A third issue is that your script is before the element it attempts to
access. because your attempt to set 'lb' is outside any function, it
is run as the page loads. Since the element with id 'Label12' hasn't
been reached yet, it doesn't exist. So even with other errors fixed,
it'll still fail.

Put the script after the element or run it onload.
 
B

bgulian

In regular asp the syntax for assigning an asp global variable to a
javascript var is:

var jscriptVar = <%=aspVar%>

I don't know if this carried over to ASP.NET.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top