ASP.NET Javascript Checkbox Question

D

dougloj

I'm developing an ASP.Net application that uses checkboxes. I am trying
to use client-side Javascript to capture the clicking of a checkbox
when it happens via the OnClick event.

In my .aspx file, I might have the checkbox coded as follows:

<asp:CheckBox onclick="SeeClick(this);" AutoPostBack="False"
Visible="True" ID="CheckBox1" Text="Selection1"
runat="server"></asp:CheckBox>

The HTML that gets sent to the browser for this is:

<span onclick="SeeClick(this);"><input id="CheckBox1" type="checkbox"
name="CheckBox1" /><label for="CheckBox1">Selection1</label></span>

In my Javascript SeeClick function, I do a few things to see if the
actual checkbox has been checked or not. That's fine. But if the user
clicks on the label next to the checkbox, the SeeClick function is
called twice, and that screws things up, because on one of the calls, I
get an invalid reading of the "checked" attribute. I have no way of
knowing if the user clicked the checkbox or the lable.

Does anybody have any ideas on how to deal with this? Thanks in
advance.

- Doug
 
K

kaeli

I have no way of
knowing if the user clicked the checkbox or the lable.

Sure you do. Check the object type. (typeof)

if (typeof varname == "checkbox")

--
 
D

dougloj

Thanks for your input, however typeof simply returns "object"
regardless of whether the checkbox or the lable is clicked. Is there
something that I'm missing?

TIA

- Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top