Menu

#2 saja.js: getForm()-implementation not correct

open
nobody
None
5
2007-08-28
2007-08-28
Tim Boven
No

While using the getForm()-function (in saja.js) I noticed an incorrect behaviour when used with a checkbox.
When I looked at the implemenation I saw that there is also a similar problem with radio-buttons and select-items.

I updated the implementation to work with checkboxes, I'll also include the code to work with the other elements and post an update of the code later.

Updated code to work with checkboxes:

getForm: function(f){
var vals = {};
for(var i=0; i<f.length; i++)
if(f[i].id) {
if (f[i].type) {
var type = f[i].type.toLowerCase()
if (type == "checkbox") {
if (f[i].checked)
vals[f[i].id] = f[i].value;
else vals[f[i].id] = '';
}
else vals[f[i].id] = f[i].value;
//FIXME: Also for radio & select
}
else {
vals[f[i].id] = f[i].value;
}
}
return vals;
}

Discussion


Log in to post a comment.