473,383 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Getting value from asp:label into javascript input value

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

Aug 5 '05 #1
10 31654
"Dwizz" <Dw*****@yahoo.co.uk> wrote in message
news:11********************@g47g2000cwa.googlegrou ps.com...
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);
....

--
Dag.
Aug 5 '05 #2
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[]" />

Aug 5 '05 #3
ASM
Dwizz wrote:
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

--
Stephane Moriaux et son [moins] vieux Mac
Aug 5 '05 #4

Thanks for the reply ASM,
but when I use the code below I get a compiler error saying execute is
not declared
<input id="Label2" readonly="readonly" type="text"
name="unitprice[]"
value="<% execute "response.write Label" %>" />

where *Label* would be your asp Label value


Aug 5 '05 #5
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" %>" />

Aug 5 '05 #6
ASM
Dwizz wrote:
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" %>" />

--
Stephane Moriaux et son [moins] vieux Mac
Aug 5 '05 #7
"Dwizz" <Dw*****@yahoo.co.uk> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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...

--
Dag.

Aug 5 '05 #8
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 5 '05 #9
Dwizz wrote:
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):

<script type="text/javascript">
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.

--
Rob
Aug 6 '05 #10
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.

Aug 7 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: NewbieJon | last post by:
I am attempting to send the variable "sComputerName" from my ActiveX script to "GetInfo.asp" using javascript. (Having been advised this is the way to get my ActiveX variable into my ASP script) ...
2
by: J?rgen Jensen | last post by:
I have made an asp-page. When pressing Submit, the form loads a javascript, for evaluating the input values. The asp-page is being reloaded from the javascript, to save the input-values. The...
4
by: Mateo | last post by:
Hi! I have labels on my page (some are web forms controls, and some are plain HTML labels), and I need Mozilla compatibile way for reading label value. For example, in IE I can use this:...
5
by: Anton ml. Vahčič | last post by:
Hi, Can anyone tells me how can I set value of asp:Label field with JavaScript? Anton, ml. ---
2
by: John Holmes | last post by:
I would like to turn on a label control in javascript with the onfocus event of another control by setting the Visible property to true. When I try and reference this label control it says...
2
by: tshad | last post by:
Is there another way to put labels on a page other than asp:label? I have been building a page where I use a label to display the calculated result of some imput. I do it using Javascript. But...
4
by: Patrick.O.Ige | last post by:
I'm DataBinding a CheckBoxList and i want to get the checkboxes selected when the page is loaded depending on a Boolean value from the Database.. chkDebtor.DataSource = objDR...
8
by: david | last post by:
I have developed a web form by using visual Studio. My question is: (1) what is the problem? (2) what is right way to do it? In the form, there are labels with id: lblWear, lblColor, and...
4
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.