View Full Version : Clear all Text inputs.

09-15-2006, 06:39 PM
I keep asking this in other places and keep getting the "standard" answers which ignore the fact that I'm trying to do this on AjaxTabs.

The previous developers created a page where database criteria are selected in a series of list boxes on the left side of the page. Selecting an option in the first box populates the available choices in the next box and so on until they are all selected. Once this happens, Each of the 6 tabs is populated with data. Most of these elements are text boxes and they are named Text1 through Text33. Some fields appear more than once. For example, Text5 appears on 3 of the 5 tabs. The ClearData function would make a series of calls like this:
if (document.getElementById('Text32')) {
document.getElementById('Text32').value = ""

While this works, it is obviously not the optimal way to clear out text elements.

What I'm trying to do is get a collection of all "input" elements and loop through them. If an item is of type "text" I set the value to "". The code I'm currently using is here:

try {
var inputs = document.getElementsByTagName("input");
for(var i=0; i < inputs.length; i++) {
//alert("inputs[" + i + "]=" + inputs[i].type + "\nName:" + inputs[i].name + "\nID:" + inputs[i].id);
if(inputs[i].type == "text") {
inputs[i].value = "";
catch(e) {
var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
alert("cleardata - Error:\ni=" + i + "\n" + "elements on form=" + document.forms[i].elements.length +"\n" + msg);

This code has two major problems. First of all, it keeps giving me the 'null' is null or not an object. I know what it means but not why I'm getting it. The second problem is that only text fields on the tab in front are getting cleared. Can anyone help me with this?