function BuildInStr(field) {
var b = field.length;
var a = '';
document.formName.Result.value = "";
if (typeof(field.length) == "undefined")
{
if(field.checked == 1){a = field.value + ',' ;}
}
for (i = 0; i < b; i++) { if(field[i].checked == 1){a = a + field[i].value + ',' ;} } a = a.substring(0,(a.length)-1); document.formName.Result.value = a; }

This function allows you to build a string from selected checkboxes, ready for use in an SQL statement
If 2 checkbox values are selected e.g. '123' and '456'and you want to use them in an "IN ()" SQL statement.
This function will provide the result '(123,456)'
The result will be placed in the field 'document.formName.Result'
just pass the field name into the function e.g. onClick="BuildInStr(document.frmName.checkBoxName);"

How to get checkbox values into a string ready to insert into MySQL

Leave a Reply

Your email address will not be published. Required fields are marked *

twenty eight + = thirty one