PDA

Click to See Complete Forum and Search --> : adding items to..


merhaba
Nov 9th, 2003, 12:46 PM
Help me to add new words/items to the list of an ARRAY using either a"prompt" or a "a textbox"..
I mean ,any time I input a new name let me see it is listed in the source of my HTML page is this possible?
what I am really tring to do is a kind of a lottary .I will then select 5 names out of those listed in the ARRAY..randomly
thanks in advance.:wave:

Acidic
Nov 9th, 2003, 01:38 PM
let me see if I understand:
you enter a name in a textfield. This name then gets added into an array. Another button then chooses a random item from that array.

now, when a name is added, should it be added permanently to the page? so that you could come on on another PC and see the name there. Or should the whole list clear when the user leaves the page?

If you dont want it permanent, then just do this:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
list = new Array()
function add() {
document.getElementById('list').innerHTML = ""
list[list.length] = document.getElementById('name').value
for (i=0; i<list.length; i++)
{
document.getElementById('list').innerHTML += list[i] + "<br>"
}
}
function choose() {
alert(list[Math.round(Math.random()*(list.length-1))])
}
</script>
</head>

<body>
<input type="text" value="enter name here" name="name">
<input type="button" value="add" onClick="add()"><br>
<input type="button" value="choose random" onClick="choose()">
<br>
<span id="list"></span>
</body>
</html>


If you want it permanent, then I would suggest PHP.