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: 开发者_Go百科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)" ...
精彩评论