Saturday, March 1, 2008

Struts Multi-Select Form Wipes out Data

I had a multiple select box in a form into which users could add/remove some attributes. On submitting the system was supposed to update the database with additions/removals done by the user.

But every time i submitted the form, all the records in the specific table was getting deleted. After spending a considerable amount of time scratching my head, i tried to set the focus on that field prior to submitting the form and then it worked.

var options = document.getElementById("selectedKeys").options;
for (var i = 0; i < options.length; i++) {
options[i].selected = true;
}
form.submit();

I am not sure if it is anything to do with Struts forms, or HTML in general.

No comments: