Home All Groups Group Topic Archive Search About

Updating server side label's value with client side javascript.

Author
27 Mar 2006 9:22 PM
sameer
guys,
Environment : ASP.NET 1.1
this is gong to be really simple for your pros out their, my aspx page has
the following server side controls, a label( contains a numeric value), a
checkbox and a submit button, the button post back to the server but not the
other two controls. All i want to do is when the user clicks on the checkbox,
i want the value of my lable control to be set to value in the lable + 1 and
i want to do this on the client side using javascript. the only problem i am
having is when i wrote down my java script, it does not update the value of
the lable, i am assuming this is because it is rendered as a <SPAN> tag in
html .this is what become of my label

    <span id="Label1" style="width:208px;">1</span>

so i am assuming this is the reason why my java script is not able to find
andupdate the lable, can any one tell me why this is happening and how can i
make it work so that when the user cliks on the checkbox , the value of lable
becomes 2 ( i.e existing value of 1 + 1) and that too all on the client side.

thanks

Sameer

Author
27 Mar 2006 9:28 PM
Phillip Williams
var lbl1= document.getElementById("Label1");
var lbl2= document.getElementById("Label2");
lbl2.innerText= parseFloat(lbl1.innerText) + parseFloat(lbl2.innerText) ;

Show quoteHide quote
"sameer" wrote:

> guys,
> Environment : ASP.NET 1.1
> this is gong to be really simple for your pros out their, my aspx page has
> the following server side controls, a label( contains a numeric value), a
> checkbox and a submit button, the button post back to the server but not the
> other two controls. All i want to do is when the user clicks on the checkbox,
> i want the value of my lable control to be set to value in the lable + 1 and
> i want to do this on the client side using javascript. the only problem i am
> having is when i wrote down my java script, it does not update the value of
> the lable, i am assuming this is because it is rendered as a <SPAN> tag in
> html .this is what become of my label
>
>     <span id="Label1" style="width:208px;">1</span>
>
> so i am assuming this is the reason why my java script is not able to find
> andupdate the lable, can any one tell me why this is happening and how can i
> make it work so that when the user cliks on the checkbox , the value of lable
> becomes 2 ( i.e existing value of 1 + 1) and that too all on the client side.
>
> thanks
>
> Sameer
>
Author
27 Mar 2006 9:57 PM
Phillip Williams
Forgot to say that the javascript code would update the display but if you
intended to use the updated value on the server side then you have to save
the value to a hidden input object that you retrieve its value on the server
side

Show quoteHide quote
"Phillip Williams" wrote:

> var lbl1= document.getElementById("Label1");
> var lbl2= document.getElementById("Label2");
> lbl2.innerText= parseFloat(lbl1.innerText) + parseFloat(lbl2.innerText) ;
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "sameer" wrote:
>
> > guys,
> > Environment : ASP.NET 1.1
> > this is gong to be really simple for your pros out their, my aspx page has
> > the following server side controls, a label( contains a numeric value), a
> > checkbox and a submit button, the button post back to the server but not the
> > other two controls. All i want to do is when the user clicks on the checkbox,
> > i want the value of my lable control to be set to value in the lable + 1 and
> > i want to do this on the client side using javascript. the only problem i am
> > having is when i wrote down my java script, it does not update the value of
> > the lable, i am assuming this is because it is rendered as a <SPAN> tag in
> > html .this is what become of my label
> >
> >     <span id="Label1" style="width:208px;">1</span>
> >
> > so i am assuming this is the reason why my java script is not able to find
> > andupdate the lable, can any one tell me why this is happening and how can i
> > make it work so that when the user cliks on the checkbox , the value of lable
> > becomes 2 ( i.e existing value of 1 + 1) and that too all on the client side.
> >
> > thanks
> >
> > Sameer
> >