Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Object | Q1564 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.