View Full Version : best way of checking if existant
scroots
01-31-2003, 07:43 PM
if i generate a random number how can i make it into a list with the other generated numbers and check to see if it alread exists and if it does perform a function?
afterward i would like to write the random numbers to a textbox
thanks in advance
scroots
Danne
01-31-2003, 08:47 PM
Something like this?
<script language="JavaScript">
function searchList(list,nr)
{
var i;
for(i=0;i<list.length;i++)
if(list[i]==nr)
return i;
return -1;
}
function addRandom()
{
var nr=Math.round(Math.random()*100);
if(searchList(randomList,nr)==-1)
randomList[randomList.length]=nr;
}
function showList(txt,list)
{
txt.value=list.join("\n");
}
var randomList=new Array();
</script>
<input type="button" value="Add number" onClick="addRandom();showList(textbox,randomList);">
<textarea id="textbox" rows="10" cols="10"></textarea>
It only adds the number if it doesn't previously exist in the array.
scroots
01-31-2003, 08:54 PM
thank you so much for that
scroots
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.