How to clear checkboxes?

B

Bill S.

Hi,

I have a form that is generated by an ASP page,
and I want to write a client-side function in
JavaScript to clear all the checkboxes in a form.

The problem is that the number of items on the form
depends on records in a database, and all the checkboxes
have the same name, ie:

<form name="myForm" method="post" action="MyPage.asp">
 
T

Thomas 'PointedEars' Lahn

Bill said:
I have a form that is generated by an ASP page,
and I want to write a client-side function in
JavaScript to clear all the checkboxes in a form.

The problem is that the number of items on the form
depends on records in a database, and all the checkboxes
have the same name, ie:
[...]

Is there another way to do this in JavaScript?

Another way? You have not even shown your way.

Anyway :) elements of the same name create a collection.
You can iterate this collection:

var c = document.forms[...].elements["..."];
if (c)
{
for (var i = 0; i < c.length; i++)
{
c.checked = false;
}
}


HTH

PointedEars
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top