Hello I'm trying to make my form so when you try to input your name it will randomly pick one from the array and insert that but i cant seem to get it to work.
<script type="text/javascript">
var val=""
var counter="0"
Name=new array()
DOB=new array()
POB=new array()
Name[0]="Donald Trump";
Name[1]="Tony Abbott";
Name[2]="Malcolm Turnbull";
Name[3]="Kevin Rudd";
Name[4]="Bill Shorten";
DOB[0]="14/06/1964";
DOB[1]="4/11/1957";
DOB[2]="24/10/1954";
DOB[3]="21/11/1957";
DOB[4]="12/05/1967
POB[0]="New York";
POB[1]="London UK";
POB[2]="Sydney";
POB[3]="Nambour";
POB[4]="Melbourne";
x=[Math.floor(Math.random() * Name.length)
function changer(){
if (counter>=Name[x].lenght){
return false}
else{
val+=Name[x].charAt(counter)
document.myform.mytext.value=val
counter++
return false
}
}
function resetit(){
alert("Thanks for feed back. Have a nice day.")
document.myform.mytext.value=""
counter="0"
val=""
x=[Math.floor(Math.random() * Name.length)
}
</script>
Aucun commentaire:
Enregistrer un commentaire