views:

32

answers:

2

I would like to pick some of your brains on this matter...

I've got a large form where there are a lot of multiple selection choices. Some are radio groups and yet others are "select all that apply" checkbox groups.

I'm trying to figure out the best way to translate each of these selections within my XML tree to send to the SQL server.

For radio groups, that's easy... one is selected: option = id #

But for checkboxes, this is a little different... I'd like to stick to sending 1 or 0 for selected or not selected. But checkbox dont have a value and so I have to check to see whether or not it's selected: true or false/yes or no.

What do you think would be the best way to convey whether or checkbox within a group of checkboxes has been selected within the XML tree?

A: 

Use a boolean throughout?

spin-docta
I'm trying to keep it all the same... but I'm starting to think that it's not possible. For the radiogroups, I'm passing an ID. But for checkboxes that doesn't apply.
dcolumbus
A: 

One way (and the simplest) would be to send only those checked and the server will assume the others are not checked. The other way would be to iterate over your form elements, select the checkboxes and see if they are checked or not, one by one. Something like:

var checkboxes = []; // assoc array of all checkboxes

function formValidate(form)
{
    var list = form.getElementsByTagName('input')
    for (var i in list)
    {
        var elem = list[i];
        if (elem.type == 'checkbox')
            checkboxes[elem.name] = elem.checked;
    }
    return true; // assuming this is an onSubmit event
}

and in your HTML:

<form onSubmit="return formValidate(this)" ...
mojuba
Yeah, I agree that not sending the unchecked makes sense. Now, I'll need to iterate through and build the XML tree as I go through. I'm using jQuery and the Validation plugin... any other pointers?
dcolumbus
mojuba