Hey guys, I need some help with the following script:
[QUOTE]
<html>
<head>
<title></title>
</head>
<body>
<script type=”text/javascript”>
var a = new Array();
function list()
{ var s = “”;
for(i = 0; i < a.length; i++)
s = s + a[i] + “n”;
alert(s); }
function add()
{ var myTextField = document.getElementById(“myText”);
if (document.getElementById(“myText”).value.length == 0)
{ alert(“Enter a Name”);
return false; }
a[a.length] = myTextField.value;
myTextField.value = “”;
return true;
}
function find()
{var myTextField = document.getElementById(“myText”);
if (document.getElementById(“myText”).value.length == 0)
{ alert(“Enter a Name”);
return false; }
else if (document.getElementById(“myText”).value != a)
{ alert(“Your Name not found”);
return false; }
else if (document.getElementById(“myText”).value == a)
{ alert(“Your Name found”);
return true; }
}
</script>
<input type=”text” id=”myText” /><br>
<input type=”button” onclick=”add()” value=”Add a name” />
<input type=”button” onclick=”list()” value=”List the names” />
<input type=”button” onclick=”find()” value=”Find” />
</body>
</html>
Everything works but I have the following bug.
When only one name is added to the array, the find function works great.
When more than one names are added to the array the find function brakes…
Any ideas or help in order to understand and solve the problem will be very appreciated.