Strange problem going on here. I'm developing a JSR168 portlet that is using Spring and the Spring form taglib.
I have a search form on a page to go through a catalog of reports based on the criteria the user selects, and for the most part it works fine. However, there is one sequence of events that is triggering an error.
I have a JavaScript function that I found to clear the 7 criteria the user can specify. It clears all of the textboxes, sets the selected index of all drop down lists to 0, and defaults a group of radio buttons to the one I want defaulted. So that's all well and good and it works just fine.
Following are 2 scenarios, 1 that demonstrates it working as intended, and 1 showing the bug.
- Type in something
- Click Search
- Results are shown
- Click Search
- Results are shown (same as before)
- Type in something new and click search
- Results are shown (new, correct results)
Here's the error
- Type in something
- Click Search
- Results are shown
- Click "Clear Form" which runs the JavaScript
- Form is cleared
- [Optional, it doesn't change anything: type in something]
- Click Search
- No change in results <-- Here's the bug
- Click Search again
- Proper results are now shown
Here's the JavaScript for reference (I have no idea if this is good or bad JS, I haven't written any in the past)
function clearForm(oForm) {
var elements = oForm.elements;
oForm.reset();
for(i=0; i<elements.length; i++) {
field_type = elements[i].type.toLowerCase();
switch(field_type) {
case "text":
case "password":
case "textarea":
case "hidden":
elements[i].value = "";
break;
case "radio":
case "checkbox":
if (elements[i].checked) {
elements[i].checked = false;
}
break;
case "select-one":
case "select-multi":
elements[i].selectedIndex = 0;
break;
default:
break;
}
}
}