How JS get the checkbox value?

Hi

I have a aspx form which has a asp:checkbox with checked=true by default

In the js, cald(), If ctl01_soldstock checked, then txtrate = empty
If ctl01_soldstock not checked, then txtrate = input value

I wrote alert(frm.ctl01_soldstock.value)  to see the value return 'on'

How should I know the soldstock checkbox value being checked or not ?

 








<asp:checkbox Runat="server" ID="soldstock" CssClass="form" Checked=true onchange="cald();" />
 
<input id="ctl01_soldstock" type="checkbox" name="ctl01$soldstock" checked="checked" />
 
function cald() {             
            var frm=document.forms[0];             
            alert(frm.ctl01_soldstock.value)    
            var rate     = frm.ctl01_txtrate.value;

Open in new window

techquesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David S.Commented:
The checked property can tell you if the checkbox is checked or not.
function cald() {             
            var frm=document.forms[0];             
            alert(frm.ctl01_soldstock.checked)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pratima PharandeCommented:
try onlcick

 <asp:checkbox Runat="server" ID="soldstock" CssClass="form" Checked=true  onclick="cald(); " />
0
ChristianSchabCommented:
Hello,

add an "value" attribute to your checkbox?
<input id="ctl01_soldstock" type="checkbox" name="ctl01$soldstock" checked="checked" value="on"/>

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

techquesAuthor Commented:
it does work, may I ask how can I assign frm.ctl01_soldstock to be checked or unchecked in js?
can the following code do it?



frm.ctl01_soldstock.checked = true;
frm.ctl01_soldstock.checked = false;

Open in new window

0
David S.Commented:
Yes, that's the best way to do it.  setAttribute() can also be used, but it tends to be buggy in IE.
0
techquesAuthor Commented:
How about if I need to disable the checkbox?

Does it?
frm.ctl01_soldstock.disabled = true;
frm.ctl01_soldstock.disabled = false;

Open in new window

0
David S.Commented:
Yes.
0
techquesAuthor Commented:
Thanks for help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.