hopup
hopup

Reputation: 75

Why is this javascript auto fill multiple fields not working?

I'm new to JavaScript and I can't figure out why this code isn't working. I want to have the user input data at the meta input table and have them click [input] to input the data in all of the rows for each column, for instance if 12/22/2012 is put for born and input is clicked, all fields under 'born' should be filled for both male and female tables. I copied the code for the html from the page into a jsfiddle, http://jsfiddle.net/hopup/h2jjd/3/

Any help appreciated, please remember I'm new to JavaScript so constructive criticism would be nice.

here is the Javascript

EDIT 2: Made some changes to my code, am I getting closer? It still does not work.

EDIT 3:THis works on chrome, but not on firefox. Any thoughts?

http://jsfiddle.net/hopup/h2jjd/5/ <-- check this one

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

numRows = document.getElementById('malesTable').rows.length + document.getElementById('femalesTable').rows.length - 2;
toCopy = document.getElementById(colname.id).value;
i = 1;
for (i; i <= numRows; i++){
    iterated_name = colname.id + "_" + i;
    document.getElementById(iterated_name).value = toCopy;
    }
}

Upvotes: 0

Views: 336

Answers (2)

Bergi
Bergi

Reputation: 664405

The line

   document.myform.count.value = document.getElementByName(name);

seems to be the odd one. Three errors I've spotted:

  • The code accesses the "count" property (a form element named "count") of the form. You seem to want document.myform.elements[count]
  • There is only a getElement/s/ByName method, which returns a NodeList of elements. You might want to use ids, there is getElementById() to return only the one element with the unique id.
  • the getElement-function returns a Node / an Element, not its content. So use textContent or access the element's text nodes.

Upvotes: 2

Pointy
Pointy

Reputation: 413720

There are illegal characters in your JavaScript source file.

edit looks like a non-Western glyph, U+8B80 - 讀 The version you posted in the question is not the same, at least not exactly.

edit ah durrr it's UTF-8, not UTF-16 of course. It's a zero-width space, as @Pumbaa80 points out. Oh, and specifically this is in the file mausdb.js.

Upvotes: 0

Related Questions