473,385 Members | 1,693 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,385 software developers and data experts.

JavaScript assigns a value to label control text value?

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 lblQuality.
Now I need to assign values to those label dynamically.
I have javascript:
function regTriples(id){
if (id==1){
document.Form1.lblWear.value="Shirt";
document.Form1.lblColor.value="Brown";
document.Form1.lblQuality.value="Honesty";
}
else if (id==2){
document.Form1.lblWear.value="Shoes";
document.Form1.lblColor.value="Black";
document.Form1.lblQuality.value="Modesty";
}
else if (id==3){
document.Form1.lblWear.value="Socks";
document.Form1.lblColor.value="Blue";
document.Form1.lblQuality.value="Charity";

}
}

When I click button which enables the JavaScript and assign those perdefined
values to the Labels, I got error from the bottom coner of the webbrowser IE:
"document.Form1.lblWear.value is null or not an object"
The following HTML code is from the source of web browser, which is
generated by web form .aspx file on the server. The default values have been
assigned when label control created on the webform.
<span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px; POSITION:
absolute; TOP: 232px">Shirt</span><span id="lblColor"
style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute; TOP:
256px">Brown</span><span id="lblQuality" style="font-size:12pt;Z-INDEX: 162;
LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
Thanks

David
May 24 '06 #1
8 3752
Use getElementByID('') like this:

document.getElementById('<%=lblWear.ClientID%>').v alue = 'Shirt';

<%=lblWear.ClientID%> this will get you the "real" id of the control after
INamingContainer get finished with it.

We use this all the time, works like a champ.

-Wayne


"david" <da***@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
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 lblQuality.
Now I need to assign values to those label dynamically.
I have javascript:
function regTriples(id){
if (id==1){
document.Form1.lblWear.value="Shirt";
document.Form1.lblColor.value="Brown";
document.Form1.lblQuality.value="Honesty";
}
else if (id==2){
document.Form1.lblWear.value="Shoes";
document.Form1.lblColor.value="Black";
document.Form1.lblQuality.value="Modesty";
}
else if (id==3){
document.Form1.lblWear.value="Socks";
document.Form1.lblColor.value="Blue";
document.Form1.lblQuality.value="Charity";

}
}

When I click button which enables the JavaScript and assign those
perdefined
values to the Labels, I got error from the bottom coner of the webbrowser
IE:
"document.Form1.lblWear.value is null or not an object"
The following HTML code is from the source of web browser, which is
generated by web form .aspx file on the server. The default values have
been
assigned when label control created on the webform.
<span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px;
POSITION:
absolute; TOP: 232px">Shirt</span><span id="lblColor"
style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute; TOP:
256px">Brown</span><span id="lblQuality" style="font-size:12pt;Z-INDEX:
162;
LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
Thanks

David

May 24 '06 #2
Thank you.

I will try it.

David

"Wayne" wrote:
Use getElementByID('') like this:

document.getElementById('<%=lblWear.ClientID%>').v alue = 'Shirt';

<%=lblWear.ClientID%> this will get you the "real" id of the control after
INamingContainer get finished with it.

We use this all the time, works like a champ.

-Wayne


"david" <da***@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
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 lblQuality.
Now I need to assign values to those label dynamically.
I have javascript:
function regTriples(id){
if (id==1){
document.Form1.lblWear.value="Shirt";
document.Form1.lblColor.value="Brown";
document.Form1.lblQuality.value="Honesty";
}
else if (id==2){
document.Form1.lblWear.value="Shoes";
document.Form1.lblColor.value="Black";
document.Form1.lblQuality.value="Modesty";
}
else if (id==3){
document.Form1.lblWear.value="Socks";
document.Form1.lblColor.value="Blue";
document.Form1.lblQuality.value="Charity";

}
}

When I click button which enables the JavaScript and assign those
perdefined
values to the Labels, I got error from the bottom coner of the webbrowser
IE:
"document.Form1.lblWear.value is null or not an object"
The following HTML code is from the source of web browser, which is
generated by web form .aspx file on the server. The default values have
been
assigned when label control created on the webform.
<span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px;
POSITION:
absolute; TOP: 232px">Shirt</span><span id="lblColor"
style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute; TOP:
256px">Brown</span><span id="lblQuality" style="font-size:12pt;Z-INDEX:
162;
LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
Thanks

David


May 24 '06 #3
Hi, Wayne:

I have tried it. There is no error message, but the labels do not change.
Here is my javascript:
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').v alue='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). value='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').v alue='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). value='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').v alue='Socks'
document.getElementById('<%=lblColor.ClientID%>'). value='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Charity'

}
}

and VB code for radio buttons in server side:

rbtnReg1.Attributes.Add("onClick", "regTriples(1)")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "regTriples(2)")
rbtnReg3.Attributes.Add("onClick", "regTriples(3)")

"Wayne" wrote:
Use getElementByID('') like this:

document.getElementById('<%=lblWear.ClientID%>').v alue = 'Shirt';

<%=lblWear.ClientID%> this will get you the "real" id of the control after
INamingContainer get finished with it.

We use this all the time, works like a champ.

-Wayne


"david" <da***@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
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 lblQuality.
Now I need to assign values to those label dynamically.
I have javascript:
function regTriples(id){
if (id==1){
document.Form1.lblWear.value="Shirt";
document.Form1.lblColor.value="Brown";
document.Form1.lblQuality.value="Honesty";
}
else if (id==2){
document.Form1.lblWear.value="Shoes";
document.Form1.lblColor.value="Black";
document.Form1.lblQuality.value="Modesty";
}
else if (id==3){
document.Form1.lblWear.value="Socks";
document.Form1.lblColor.value="Blue";
document.Form1.lblQuality.value="Charity";

}
}

When I click button which enables the JavaScript and assign those
perdefined
values to the Labels, I got error from the bottom coner of the webbrowser
IE:
"document.Form1.lblWear.value is null or not an object"
The following HTML code is from the source of web browser, which is
generated by web form .aspx file on the server. The default values have
been
assigned when label control created on the webform.
<span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px;
POSITION:
absolute; TOP: 232px">Shirt</span><span id="lblColor"
style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute; TOP:
256px">Brown</span><span id="lblQuality" style="font-size:12pt;Z-INDEX:
162;
LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
Thanks

David


May 24 '06 #4
The label write a span tag. Use .innerText instead of .value

FYI, you may want to return false at the end if you don't want the button to
cause a post back.

Changes for the return false to prevent postback and the .innerText are made
below.

Hope this helps.

-Wayne
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Socks'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Charity'

}

return false
}
rbtnReg1.Attributes.Add("onClick", "return regTriples(1);")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "return regTriples(2);")
rbtnReg3.Attributes.Add("onClick", "return regTriples(3);")



"david" <da***@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
Hi, Wayne:

I have tried it. There is no error message, but the labels do not change.
Here is my javascript:
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').v alue='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). value='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').v alue='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). value='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').v alue='Socks'
document.getElementById('<%=lblColor.ClientID%>'). value='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Charity'

}
}

and VB code for radio buttons in server side:

rbtnReg1.Attributes.Add("onClick", "regTriples(1)")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "regTriples(2)")
rbtnReg3.Attributes.Add("onClick", "regTriples(3)")

"Wayne" wrote:
Use getElementByID('') like this:

document.getElementById('<%=lblWear.ClientID%>').v alue = 'Shirt';

<%=lblWear.ClientID%> this will get you the "real" id of the control
after
INamingContainer get finished with it.

We use this all the time, works like a champ.

-Wayne


"david" <da***@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
>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 lblQuality.
> Now I need to assign values to those label dynamically.
> I have javascript:
> function regTriples(id){
> if (id==1){
> document.Form1.lblWear.value="Shirt";
> document.Form1.lblColor.value="Brown";
> document.Form1.lblQuality.value="Honesty";
> }
> else if (id==2){
> document.Form1.lblWear.value="Shoes";
> document.Form1.lblColor.value="Black";
> document.Form1.lblQuality.value="Modesty";
> }
> else if (id==3){
> document.Form1.lblWear.value="Socks";
> document.Form1.lblColor.value="Blue";
> document.Form1.lblQuality.value="Charity";
>
> }
>
>
> }
>
> When I click button which enables the JavaScript and assign those
> perdefined
> values to the Labels, I got error from the bottom coner of the
> webbrowser
> IE:
> "document.Form1.lblWear.value is null or not an object"
>
>
> The following HTML code is from the source of web browser, which is
> generated by web form .aspx file on the server. The default values have
> been
> assigned when label control created on the webform.
>
>
> <span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px;
> POSITION:
> absolute; TOP: 232px">Shirt</span><span id="lblColor"
> style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute;
> TOP:
> 256px">Brown</span><span id="lblQuality" style="font-size:12pt;Z-INDEX:
> 162;
> LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
>
>
> Thanks
>
> David


May 24 '06 #5
My button postback has been disabled.

I will try it

David

"Wayne" wrote:
The label write a span tag. Use .innerText instead of .value

FYI, you may want to return false at the end if you don't want the button to
cause a post back.

Changes for the return false to prevent postback and the .innerText are made
below.

Hope this helps.

-Wayne
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Socks'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Charity'

}

return false
}
rbtnReg1.Attributes.Add("onClick", "return regTriples(1);")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "return regTriples(2);")
rbtnReg3.Attributes.Add("onClick", "return regTriples(3);")



"david" <da***@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
Hi, Wayne:

I have tried it. There is no error message, but the labels do not change.
Here is my javascript:
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').v alue='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). value='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').v alue='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). value='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').v alue='Socks'
document.getElementById('<%=lblColor.ClientID%>'). value='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Charity'

}
}

and VB code for radio buttons in server side:

rbtnReg1.Attributes.Add("onClick", "regTriples(1)")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "regTriples(2)")
rbtnReg3.Attributes.Add("onClick", "regTriples(3)")

"Wayne" wrote:
Use getElementByID('') like this:

document.getElementById('<%=lblWear.ClientID%>').v alue = 'Shirt';

<%=lblWear.ClientID%> this will get you the "real" id of the control
after
INamingContainer get finished with it.

We use this all the time, works like a champ.

-Wayne


"david" <da***@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
>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 lblQuality.
> Now I need to assign values to those label dynamically.
> I have javascript:
> function regTriples(id){
> if (id==1){
> document.Form1.lblWear.value="Shirt";
> document.Form1.lblColor.value="Brown";
> document.Form1.lblQuality.value="Honesty";
> }
> else if (id==2){
> document.Form1.lblWear.value="Shoes";
> document.Form1.lblColor.value="Black";
> document.Form1.lblQuality.value="Modesty";
> }
> else if (id==3){
> document.Form1.lblWear.value="Socks";
> document.Form1.lblColor.value="Blue";
> document.Form1.lblQuality.value="Charity";
>
> }
>
>
> }
>
> When I click button which enables the JavaScript and assign those
> perdefined
> values to the Labels, I got error from the bottom coner of the
> webbrowser
> IE:
> "document.Form1.lblWear.value is null or not an object"
>
>
> The following HTML code is from the source of web browser, which is
> generated by web form .aspx file on the server. The default values have
> been
> assigned when label control created on the webform.
>
>
> <span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px;
> POSITION:
> absolute; TOP: 232px">Shirt</span><span id="lblColor"
> style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute;
> TOP:
> 256px">Brown</span><span id="lblQuality" style="font-size:12pt;Z-INDEX:
> 162;
> LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
>
>
> Thanks
>
> David


May 24 '06 #6
Thank you, Wayne.

It works!

I have a lot to learn.

Do you have good books or web sites to recommend for reading?

David

"Wayne" wrote:
The label write a span tag. Use .innerText instead of .value

FYI, you may want to return false at the end if you don't want the button to
cause a post back.

Changes for the return false to prevent postback and the .innerText are made
below.

Hope this helps.

-Wayne
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Socks'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Charity'

}

return false
}
rbtnReg1.Attributes.Add("onClick", "return regTriples(1);")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "return regTriples(2);")
rbtnReg3.Attributes.Add("onClick", "return regTriples(3);")



"david" <da***@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
Hi, Wayne:

I have tried it. There is no error message, but the labels do not change.
Here is my javascript:
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').v alue='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). value='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').v alue='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). value='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').v alue='Socks'
document.getElementById('<%=lblColor.ClientID%>'). value='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).value='Charity'

}
}

and VB code for radio buttons in server side:

rbtnReg1.Attributes.Add("onClick", "regTriples(1)")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "regTriples(2)")
rbtnReg3.Attributes.Add("onClick", "regTriples(3)")

"Wayne" wrote:
Use getElementByID('') like this:

document.getElementById('<%=lblWear.ClientID%>').v alue = 'Shirt';

<%=lblWear.ClientID%> this will get you the "real" id of the control
after
INamingContainer get finished with it.

We use this all the time, works like a champ.

-Wayne


"david" <da***@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
>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 lblQuality.
> Now I need to assign values to those label dynamically.
> I have javascript:
> function regTriples(id){
> if (id==1){
> document.Form1.lblWear.value="Shirt";
> document.Form1.lblColor.value="Brown";
> document.Form1.lblQuality.value="Honesty";
> }
> else if (id==2){
> document.Form1.lblWear.value="Shoes";
> document.Form1.lblColor.value="Black";
> document.Form1.lblQuality.value="Modesty";
> }
> else if (id==3){
> document.Form1.lblWear.value="Socks";
> document.Form1.lblColor.value="Blue";
> document.Form1.lblQuality.value="Charity";
>
> }
>
>
> }
>
> When I click button which enables the JavaScript and assign those
> perdefined
> values to the Labels, I got error from the bottom coner of the
> webbrowser
> IE:
> "document.Form1.lblWear.value is null or not an object"
>
>
> The following HTML code is from the source of web browser, which is
> generated by web form .aspx file on the server. The default values have
> been
> assigned when label control created on the webform.
>
>
> <span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px;
> POSITION:
> absolute; TOP: 232px">Shirt</span><span id="lblColor"
> style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute;
> TOP:
> 256px">Brown</span><span id="lblQuality" style="font-size:12pt;Z-INDEX:
> 162;
> LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
>
>
> Thanks
>
> David


May 24 '06 #7
I wished there was, the best site for this is GOOGLE.com and have 5 very
cleaver programmer and designers help. Google is our life saver.

Working with JavaScript and ASP.NET is a very difficult topic to find
information on. We searched a long time for that solution. It's not what
you do in ASP.NET that counts, it what ASP.NET does with what you did that
matters in the end.

Best of luck!

-Wayne
"david" <da***@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
Thank you, Wayne.

It works!

I have a lot to learn.

Do you have good books or web sites to recommend for reading?

David

"Wayne" wrote:
The label write a span tag. Use .innerText instead of .value

FYI, you may want to return false at the end if you don't want the button
to
cause a post back.

Changes for the return false to prevent postback and the .innerText are
made
below.

Hope this helps.

-Wayne
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Socks'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Charity'

}

return false
}
rbtnReg1.Attributes.Add("onClick", "return regTriples(1);")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "return regTriples(2);")
rbtnReg3.Attributes.Add("onClick", "return regTriples(3);")



"david" <da***@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
> Hi, Wayne:
>
> I have tried it. There is no error message, but the labels do not
> change.
> Here is my javascript:
> function regTriples(id){
> if (id==1){
>
> document.getElementById('<%=lblWear.ClientID%>').v alue='Shirt'
> document.getElementById('<%=lblColor.ClientID%>'). value='Brown'
> document.getElementById('<%=lblQuality.ClientID%>' ).value='Honesty'
> }
> else if (id==2){
>
> document.getElementById('<%=lblWear.ClientID%>').v alue='Shoes'
> document.getElementById('<%=lblColor.ClientID%>'). value='Black'
> document.getElementById('<%=lblQuality.ClientID%>' ).value='Modesty'
> }
> else if (id==3){
>
> document.getElementById('<%=lblWear.ClientID%>').v alue='Socks'
> document.getElementById('<%=lblColor.ClientID%>'). value='Blue'
> document.getElementById('<%=lblQuality.ClientID%>' ).value='Charity'
>
> }
>
>
> }
>
> and VB code for radio buttons in server side:
>
> rbtnReg1.Attributes.Add("onClick", "regTriples(1)")
> rbtnReg1.Checked = True
> rbtnReg2.Attributes.Add("onClick", "regTriples(2)")
> rbtnReg3.Attributes.Add("onClick", "regTriples(3)")
>
>
>
> "Wayne" wrote:
>
>> Use getElementByID('') like this:
>>
>> document.getElementById('<%=lblWear.ClientID%>').v alue = 'Shirt';
>>
>> <%=lblWear.ClientID%> this will get you the "real" id of the control
>> after
>> INamingContainer get finished with it.
>>
>> We use this all the time, works like a champ.
>>
>> -Wayne
>>
>>
>>
>>
>> "david" <da***@discussions.microsoft.com> wrote in message
>> news:69**********************************@microsof t.com...
>> >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 lblQuality.
>> > Now I need to assign values to those label dynamically.
>> > I have javascript:
>> > function regTriples(id){
>> > if (id==1){
>> > document.Form1.lblWear.value="Shirt";
>> > document.Form1.lblColor.value="Brown";
>> > document.Form1.lblQuality.value="Honesty";
>> > }
>> > else if (id==2){
>> > document.Form1.lblWear.value="Shoes";
>> > document.Form1.lblColor.value="Black";
>> > document.Form1.lblQuality.value="Modesty";
>> > }
>> > else if (id==3){
>> > document.Form1.lblWear.value="Socks";
>> > document.Form1.lblColor.value="Blue";
>> > document.Form1.lblQuality.value="Charity";
>> >
>> > }
>> >
>> >
>> > }
>> >
>> > When I click button which enables the JavaScript and assign those
>> > perdefined
>> > values to the Labels, I got error from the bottom coner of the
>> > webbrowser
>> > IE:
>> > "document.Form1.lblWear.value is null or not an object"
>> >
>> >
>> > The following HTML code is from the source of web browser, which is
>> > generated by web form .aspx file on the server. The default values
>> > have
>> > been
>> > assigned when label control created on the webform.
>> >
>> >
>> > <span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px;
>> > POSITION:
>> > absolute; TOP: 232px">Shirt</span><span id="lblColor"
>> > style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute;
>> > TOP:
>> > 256px">Brown</span><span id="lblQuality"
>> > style="font-size:12pt;Z-INDEX:
>> > 162;
>> > LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
>> >
>> >
>> > Thanks
>> >
>> > David
>>
>>
>>


May 24 '06 #8
Thank you again, Wayne.

I have not been here for two days.
Yes, GOOGLE.COM makes this world easy to work on.
I am used to Yahoo, but now google is the best.

David

"Wayne" wrote:
I wished there was, the best site for this is GOOGLE.com and have 5 very
cleaver programmer and designers help. Google is our life saver.

Working with JavaScript and ASP.NET is a very difficult topic to find
information on. We searched a long time for that solution. It's not what
you do in ASP.NET that counts, it what ASP.NET does with what you did that
matters in the end.

Best of luck!

-Wayne
"david" <da***@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
Thank you, Wayne.

It works!

I have a lot to learn.

Do you have good books or web sites to recommend for reading?

David

"Wayne" wrote:
The label write a span tag. Use .innerText instead of .value

FYI, you may want to return false at the end if you don't want the button
to
cause a post back.

Changes for the return false to prevent postback and the .innerText are
made
below.

Hope this helps.

-Wayne
function regTriples(id){
if (id==1){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shirt'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Brown'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Honesty'
}
else if (id==2){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Shoes'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Black'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Modesty'
}
else if (id==3){

document.getElementById('<%=lblWear.ClientID%>').i nnerText='Socks'
document.getElementById('<%=lblColor.ClientID%>'). innerText='Blue'
document.getElementById('<%=lblQuality.ClientID%>' ).innerText='Charity'

}

return false
}
rbtnReg1.Attributes.Add("onClick", "return regTriples(1);")
rbtnReg1.Checked = True
rbtnReg2.Attributes.Add("onClick", "return regTriples(2);")
rbtnReg3.Attributes.Add("onClick", "return regTriples(3);")



"david" <da***@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
> Hi, Wayne:
>
> I have tried it. There is no error message, but the labels do not
> change.
> Here is my javascript:
> function regTriples(id){
> if (id==1){
>
> document.getElementById('<%=lblWear.ClientID%>').v alue='Shirt'
> document.getElementById('<%=lblColor.ClientID%>'). value='Brown'
> document.getElementById('<%=lblQuality.ClientID%>' ).value='Honesty'
> }
> else if (id==2){
>
> document.getElementById('<%=lblWear.ClientID%>').v alue='Shoes'
> document.getElementById('<%=lblColor.ClientID%>'). value='Black'
> document.getElementById('<%=lblQuality.ClientID%>' ).value='Modesty'
> }
> else if (id==3){
>
> document.getElementById('<%=lblWear.ClientID%>').v alue='Socks'
> document.getElementById('<%=lblColor.ClientID%>'). value='Blue'
> document.getElementById('<%=lblQuality.ClientID%>' ).value='Charity'
>
> }
>
>
> }
>
> and VB code for radio buttons in server side:
>
> rbtnReg1.Attributes.Add("onClick", "regTriples(1)")
> rbtnReg1.Checked = True
> rbtnReg2.Attributes.Add("onClick", "regTriples(2)")
> rbtnReg3.Attributes.Add("onClick", "regTriples(3)")
>
>
>
> "Wayne" wrote:
>
>> Use getElementByID('') like this:
>>
>> document.getElementById('<%=lblWear.ClientID%>').v alue = 'Shirt';
>>
>> <%=lblWear.ClientID%> this will get you the "real" id of the control
>> after
>> INamingContainer get finished with it.
>>
>> We use this all the time, works like a champ.
>>
>> -Wayne
>>
>>
>>
>>
>> "david" <da***@discussions.microsoft.com> wrote in message
>> news:69**********************************@microsof t.com...
>> >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 lblQuality.
>> > Now I need to assign values to those label dynamically.
>> > I have javascript:
>> > function regTriples(id){
>> > if (id==1){
>> > document.Form1.lblWear.value="Shirt";
>> > document.Form1.lblColor.value="Brown";
>> > document.Form1.lblQuality.value="Honesty";
>> > }
>> > else if (id==2){
>> > document.Form1.lblWear.value="Shoes";
>> > document.Form1.lblColor.value="Black";
>> > document.Form1.lblQuality.value="Modesty";
>> > }
>> > else if (id==3){
>> > document.Form1.lblWear.value="Socks";
>> > document.Form1.lblColor.value="Blue";
>> > document.Form1.lblQuality.value="Charity";
>> >
>> > }
>> >
>> >
>> > }
>> >
>> > When I click button which enables the JavaScript and assign those
>> > perdefined
>> > values to the Labels, I got error from the bottom coner of the
>> > webbrowser
>> > IE:
>> > "document.Form1.lblWear.value is null or not an object"
>> >
>> >
>> > The following HTML code is from the source of web browser, which is
>> > generated by web form .aspx file on the server. The default values
>> > have
>> > been
>> > assigned when label control created on the webform.
>> >
>> >
>> > <span id="lblWear" style="font-size:12pt;Z-INDEX: 160; LEFT: 32px;
>> > POSITION:
>> > absolute; TOP: 232px">Shirt</span><span id="lblColor"
>> > style="font-size:12pt;Z-INDEX: 161; LEFT: 32px; POSITION: absolute;
>> > TOP:
>> > 256px">Brown</span><span id="lblQuality"
>> > style="font-size:12pt;Z-INDEX:
>> > 162;
>> > LEFT: 32px; POSITION: absolute; TOP: 280px">Honesty</span>
>> >
>> >
>> > Thanks
>> >
>> > David
>>
>>
>>


May 26 '06 #9

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

Similar topics

7
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I donīt know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
1
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for...
1
by: avp | last post by:
Hi, We have an ASP.NET 2.0 (C#) application that has a web form with a CheckBoxList control and a CustomValidator control. The CustomValidator control is used to validate that at least one...
6
by: drec | last post by:
I am just learning Javascript and I would like to create a basic form that gives me two options. This will be using either checkbox or radio input type, however I would like the second option to...
4
by: Ronald Raygun | last post by:
I have a form on an HTML page with the usual user name, email etc. I want to be able to display a popup window (callout?) when a text input control element is clicked. For example, for the form:...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.