[thelist] Changing Check Box values with JavaScript

Shaun M. Anderson ShaunAnderson at smarttech.com
Fri May 25 17:55:43 CDT 2001

Howdy All.

I've been messing around with this on and off for the better part of the
day, and I'm at my wits end.

We're re-designing our corporate site, and abolishing all use of the
FrontPage Extensions (Finally!!!)

I've been charged with re-creating the forms so that the data they provide
matches the FP text files that we used to get. They need to be the same
because that's what the people who enter the data from the files into the
database want. (If you're wondering why it's done by hand at all, that's
another story altogether.)

Anyway, I'm using ASP to write the textfile on the server, and it worked
fine until I noticed that I was missing fields.  When a user doesn't check a
check box and you're using the FP extensions, the text file has a blank
field. IE) you have 6 check boxes in the same group, there would be six ""
in the text file.  We used that information as place holders, so I still
need them.

The problem is that if a user doesn't check the box, nothing is sent to the
server, so I don't know what the empty fields are and therefore can't write
them to the textfile.  My solution was to use JavaScript onSubmit to check
all of the form fields, and if they are a check box (signified by their name
ending in "!check") I would check to see if it was checked or not.  If it
wasn't checked, I would change the value to "NOTCHECKED" and set .checked to
true.  Then the ASP code checks to see if the value of the form field is
NOTCHECKED.  If it is, it just writes "" to the text file.

This is the JS code I wrote, that isn't working.  So my question is, how

The error received is:

"checked" is null or not an object. (IE 5.5/Win98)


function checkChoice(Form, i)
var NumOfFields;
var FieldName;
var NameLength;

	NumOfFields = document.Form.elements.length;
	for (i=0; i <= NumOfFields; i++)
	i = 18;
	FieldName = Form[i].name;
	NameLength = FieldName.length;
		if (FieldName.substring((5, NameLength - 6)) == "!check")
			if (!Form[i].checked)
				Form[i].checked = true;
				Form[i].value = "NOTCHECKED";

<tip type="ASP">
When you're brain-storming, don't do it by yourself.
Even if you're the best person available to do the job at hand, it doesn't
necessarily mean that you've got the best ideas on that particular day.

More information about the thelist mailing list