user622639
user622639

Reputation: 37

javascript issue - firefox

Hi all Why this piece of javascript code doesn't work on firefox

var nfiles = 1;
function Expand(){
nfiles++
var adh = '<input type="file" name="File '+nfiles+'">';
files.insertAdjacentHTML('BeforeEnd',adh);
return false;
};

Upvotes: 1

Views: 85

Answers (3)

Tom
Tom

Reputation: 4180

I don't know where this function comes from, so I can't say anything about that:

files.insertAdjacentHTML('BeforeEnd',adh);

This is an alternative way of writing the following line; it feels cleare to me, but I must admit it's personal taste:

var adh = "<input type=\"file\" name=\"File " + nfiles + "\">";

and put a ; after the following line:

nfiles++

Upvotes: 2

arttronics
arttronics

Reputation: 9955

It looks like you have no semi-colon after your variable.

Shown below is a working Expand function for all browsers including Firefox.

Reference: jsFiddle.

function Expand() {
    nfiles++;
    var files = document.getElementById('test');
    var adh = '<input type="file" name="File ' + nfiles + '">';
    files.insertAdjacentHTML('afterend', adh);
    return false;
}

Upvotes: 2

me_digvijay
me_digvijay

Reputation: 5492

May be the BeforeEnd should be something like this

beforeend

See here insertAdjacentHTML

Upvotes: 0

Related Questions