0

I'm trying to modernize an intranet site somebody has built in the past which at the moment is forced into compatibility mode for IE5 through group policy. There is this javascript which creates x ammount of file input boxes within a form. This works on compatibility mode up to IE9 but not higher. I don't really know javascript I was hoping someone could help me modernize it?

<SCRIPT LANGUAGE="JavaScript">
var i = 0, j = 0;
var t1 = new Array();

function createtext() {

    var inputLoop = document.getElementById("Many");
    var table1 = document.getElementById("field");

    for (i = 0; i < inputLoop.value; i++)
    {
        t1[i] = document.createElement('input');
        t1[i].type = 'file';
        t1[i].name = 'Image' + i;
        t1[i].value = "Hello";
        t1[i].size = 20;
        document.forms[0].appendChild(t1[i]);
    }
}
</SCRIPT>

<input name="b1" type="button" onClick="createtext();" value="Add">

If I run it on higher than IE9 the 'Add' button does nothing

David H
  • 71
  • 8

1 Answers1

0

The code works even in modern browsers. Just remove t1[i].value = "Hello"; because you can't set a value to input field programmatically.

var i = 0,
  j = 0;
var t1 = [];

function createtext() {

  var inputLoop = document.getElementById("Many");
  var table1 = document.getElementById("field");

  if (inputLoop.value) {
    for (i = 0; i < inputLoop.value; i++) {
      t1[i] = document.createElement('input');
      t1[i].type = 'file';
      t1[i].name = 'Image' + i;
      t1[i].size = 20;
      document.forms[0].appendChild(t1[i]);
    }
  }
}
<input type="text" id="Many">
<input name="b1" type="button" onClick="createtext();" value="Add">


<form action=""></form>
Bojan Petkovski
  • 6,835
  • 1
  • 25
  • 34
  • Thanks for the response, I've tried just that and it doesn't seem to make a difference. I've created it in a new document as well to isolate it anything else interfering. – David H May 11 '16 at 09:32
  • Nevermind my testing was flawed, its working now - thank you! – David H May 11 '16 at 09:46