hopup
hopup

Reputation: 75

Why does this work in Chrome but not firefox?

function fill (colname) {
    var numRows, i, toCopy, iterated_name;

    numRows = document.getElementById('malesTable').rows.length + document.getElementById('femalesTable').rows.length - 2;
    //gets number of rows, subtracts two for header rows(male and female)
    toCopy = document.getElementById(colname.id).value;
    i = 1;
    //iterate over id's and input values
    for (i; i <= numRows; i++){
    iterated_name = colname.id + "_" + i;
    document.getElementById(iterated_name).value = toCopy;
    }
}

It will work in chrome to autofill many fields, however it doesn't in firefox. Why?

To clarify when inputs are put into the autofill box, it doesn't copy the fields over as intended.

Here's the jsfiddle

http://jsfiddle.net/hopup/tfEQM

Upvotes: 0

Views: 1012

Answers (1)

Boris Zbarsky
Boris Zbarsky

Reputation: 35064

When you do this:

fill(external_id);

you're passing in undefined in Firefox but passing in an element in Chrome because Chrome makes all elements with IDs pollute the global scope.

Presumably you meant fill(document.getElementById("external_id")) ?

Upvotes: 1

Related Questions