Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1564 Is it possible to generate an array based on the number the user had entered in a text field?

You are here: irt.org | FAQ | JavaScript | Object | Q1564 [ previous next ]

Try:

<html>

<head>
<script language="JavaScript"><!--
var globalVariable;

function makeArray(size) {
  // create array:
  globalVariable = new Array(parseInt(size));

  // populate array:
  for (var i=0; i<globalVariable.length; i++) {
    globalVariable[i] = 'Hello world';
  }

  // display array contents:
  var o = '';
  for (var i=0; i<globalVariable.length; i++) {
    o += globalVariable[i] + '\n';
  }
  alert(o);
}
//--></script>
</head>

<body>

<form>
<input type="text" onChange="makeArray(this.value)">
</form>

</body>

</html>

©2018 Martin Webb