简体   繁体   中英

From HTML Form to XML Tree

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?

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)" ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM