.attr('id') doesn't work if there is no ID attribute. Try using the DOM references this.id.length
and this.name.length
directly in the conditional like so:
if (this.id.length == 0 && this.name.length != 0) {
and get rid of the assignments to var id
and var name
.
Note that $j(this).id.length
does not work because .id is not a jQuery property, it is a DOM property.