|
-
Nov 9th, 2003, 01:46 PM
#1
Thread Starter
Fanatic Member
adding items to..
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.
-
Nov 9th, 2003, 02:38 PM
#2
Frenzied Member
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:
Code:
<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.
Last edited by Acidic; Nov 9th, 2003 at 02:57 PM.
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|