I have is a set of HTML checkboxes and a Access database at the back end, when I retrieve the values of the checkboxes to process with Classic ASP I am running into a problem with undefined values.

What I have discovered from research is that if a checkbox is not checked it will not passing anything as HTML checkboxes are either selected as 'on' or 'nothing'.

However if it is checked then there is an on values passed and the yes/no field in the DB is checked.

As you can imagine the DB needs a value and if an 'undefined' value is passed to a yes/no field, it results in a missing parameter error being sent.

The compiled sql statement from a Response.Write command is:

INSERT INTO tblHome (memberID, towncity, towndistance, towndirection, propertytype, flatfloor, flatblock, nobedrooms, nobathrooms, maxnoofpeople, carneeded, carexchange, smoking, swimpool, petcare, childrenallowed, plantcare, additionalinfo, picture)values ('2', 'London', '15', 'SE', 'Flat', '3', 'CC', '2', '2', '4', undefined, on, on, on, on, on, on, 'Hello', '');

*note the undefined

The question:

Is there any way to make the 'nothing/undefined' value that is sent from the unchecked checkbox into a 'off' value so that the asp doesn’t fail?

Please bear in mind that I only realy understand JavaScript and am very new to asp.

Hope that makes sense, any help would be greatly appreciated.

Thanks
Graham

You should never execute code without evaluating it first.
Since a checkbox has only two possible values a simple if...else eval will do just fine.

Smth like:

strSQL = "INSERT INTO tblHome (memberID, towncity, towndistance, towndirection, propertytype, flatfloor, flatblock, nobedrooms, nobathrooms, maxnoofpeople, carneeded, carexchange, smoking, swimpool, petcare, childrenallowed, plantcare, additionalinfo, picture)values ('2', 'London', '15', 'SE', 'Flat', '3', 'CC', '2', '2', '4', "

fields = Array("carneeded", "carexchange", "smoking", "swimpool", "petcare", "childrenallowed","plantcare")
For i = 0 to ubound(fields)
	If Request.Form(fields(i)) = "on" Then
		strSQL = strSQL & "on, "
	Else
		strSQL = strSQL & "off, "
	End If
Next

strSQL = strSQL & "'Hello', '')"
This article has been dead for over six months. Start a new discussion instead.