473,396 Members | 2,121 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,396 software developers and data experts.

How do I refer to a label in javascript?

I have a javascript function that is called when I click my server-side
submit button. I want to validate that one of my labels is not empty before
allowing a submit.
I cannot figure out how to access the value stored in myLabel.text.

For hidden form variables I use the following syntax in javascript:
myForm.myHidden.value

I tried a bunch of different things with no luck! Thanks in advance for any
help!
Nov 19 '05 #1
6 1686
you would need to make the textbox an input with a runat=server tag.
then the javascript would be able to access the form value (regarding you've
named the form as well)

an ofcourse for .net to use the html input, you'de need that runat=server
tag as well as declaring the input in the code behind

"jacobryce" <ja*******@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
I have a javascript function that is called when I click my server-side
submit button. I want to validate that one of my labels is not empty
before
allowing a submit.
I cannot figure out how to access the value stored in myLabel.text.

For hidden form variables I use the following syntax in javascript:
myForm.myHidden.value

I tried a bunch of different things with no luck! Thanks in advance for
any
help!

Nov 19 '05 #2
I think serverside labels get rendered as <span> tags. View the source of
you page to check.

Then use

document.getElementByID

google it for more details

"jacobryce" <ja*******@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
I have a javascript function that is called when I click my server-side
submit button. I want to validate that one of my labels is not empty
before
allowing a submit.
I cannot figure out how to access the value stored in myLabel.text.

For hidden form variables I use the following syntax in javascript:
myForm.myHidden.value

I tried a bunch of different things with no luck! Thanks in advance for
any
help!

Nov 19 '05 #3
Hi jacobryce,

If the label is an <asp:label> control, then you can reference it in your
javascript code as:

<code>
<script language="javascript">
var labelText = '<% = Label1.ClientID %>';
alert(labelText);
</script>
</code>

HTH,
~d
"jacobryce" <ja*******@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
I have a javascript function that is called when I click my server-side
submit button. I want to validate that one of my labels is not empty
before
allowing a submit.
I cannot figure out how to access the value stored in myLabel.text.

For hidden form variables I use the following syntax in javascript:
myForm.myHidden.value

I tried a bunch of different things with no luck! Thanks in advance for
any
help!

Nov 19 '05 #4
jacobryce wrote:
I have a javascript function that is called when I click my
server-side submit button. I want to validate that one of my labels
is not empty before allowing a submit.
I cannot figure out how to access the value stored in myLabel.text.

For hidden form variables I use the following syntax in javascript:
myForm.myHidden.value

I tried a bunch of different things with no luck! Thanks in advance
for any help!


myForm.<%=myHidden.ClientID%>.value

--

Riki
Nov 19 '05 #5
I couldn't get that to work, but I did get the following code to work:
var labelText = "<%= myLabel.Text %>";
alert(labelText);

Thank you.

"Riki" wrote:
jacobryce wrote:
I have a javascript function that is called when I click my
server-side submit button. I want to validate that one of my labels
is not empty before allowing a submit.
I cannot figure out how to access the value stored in myLabel.text.

For hidden form variables I use the following syntax in javascript:
myForm.myHidden.value

I tried a bunch of different things with no luck! Thanks in advance
for any help!


myForm.<%=myHidden.ClientID%>.value

--

Riki

Nov 19 '05 #6
Thanks, I had already tried that with no luck. But maybe my syntax was
incorrect.
alert(document.getElementById("myLabel").innerText ;

"Josh" wrote:
I think serverside labels get rendered as <span> tags. View the source of
you page to check.

Then use

document.getElementByID

google it for more details

"jacobryce" <ja*******@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
I have a javascript function that is called when I click my server-side
submit button. I want to validate that one of my labels is not empty
before
allowing a submit.
I cannot figure out how to access the value stored in myLabel.text.

For hidden form variables I use the following syntax in javascript:
myForm.myHidden.value

I tried a bunch of different things with no luck! Thanks in advance for
any
help!


Nov 19 '05 #7

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

Similar topics

2
by: knoak | last post by:
Hi there, In my form, after validation, labels of wrong fields are turned into a red color. What i want now is when you hit 'reset', to make all the labels grey again. I have the next code:...
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: Dot net work | last post by:
Hello. I have an aspx page that changes an HTML label's text using javascript. After the label's text has been changed in this way, I redirect to another aspx page. If I then use the back...
5
by: peter | last post by:
I have created an UserControl (MywindowFooter) which contains a label-component : <asp:label id="lblStatusBar" runat="server"></asp:label> How can I refer to this label, from the code-behind...
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...
3
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644"...
7
by: Sandy | last post by:
Hello - I have a form that when submitted checks the database and if the username is already taken, a label shows indicating same. I need to make that label NOT visible after the user clicks...
4
by: pradeep | last post by:
how to set input type label's value through javascript
3
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.