I have a field for input on an HTML page. I have generated buttons. But I have problem. I dont’n know how to add onclic for each button. I need to display value of buttons on my field after press on each button.
This is my code:
[CODE]
<html>
<head>
</head>
<body>
<form name=”field”>
<input type=”text” name=”input” size=”50″>
<input type=”reset”/>
</form>
<p></p>
<script>
var mylist = [‘first’, ‘second’, ‘third’, ‘fourth’, ‘fifth’]
var rand = null;
var word = null;
var threshold = 3
for (var i = 0; i < threshold; i++) {
rand = Math.floor(Math.random() * (mylist.length – 1)) + 1;
word = mylist[rand];
var btn = document.createElement(‘input’);
btn.id = ‘b’ + i;
btn.value = word;
btn.type = ‘button’;
document.body.appendChild(btn);
}
</script>
</body>
</html>