Firecrackle
09-25-2009, 10:17 AM
I'm fairly new to Javascript so greatly need some expert eyes to point me in the right direction here.
I'm making an online test and the participants would have to verify themselves by registration number before they can proceed with it. I'm trying to use an array [NoList] to index the registration numbers. This is encased in a function [checkName] that is assigned to and activated by a button. This corresponds to a text field [PartNo] where the participant puts their number and the function then checks that the input value/data matches one of the items the array index. Here is the code:
function checkName() {
var NoList = ['123456', '234561', '345612'];
Partname = document.test.PartNo.value;
for (var i in NoList) {
if (Partname != NoList[i]) {
alert("Your number "+ Partname + " has not been recognised.\nPlease check it and try again.");
return false;
}
window.open('nextstage.html');
return true;
}
}
I've done a dry run and found that the function only notices the first item in the index and ignores the others. I would be very grateful if anyone can highlight the error and suggest some alternatives. Thanks.
I'm making an online test and the participants would have to verify themselves by registration number before they can proceed with it. I'm trying to use an array [NoList] to index the registration numbers. This is encased in a function [checkName] that is assigned to and activated by a button. This corresponds to a text field [PartNo] where the participant puts their number and the function then checks that the input value/data matches one of the items the array index. Here is the code:
function checkName() {
var NoList = ['123456', '234561', '345612'];
Partname = document.test.PartNo.value;
for (var i in NoList) {
if (Partname != NoList[i]) {
alert("Your number "+ Partname + " has not been recognised.\nPlease check it and try again.");
return false;
}
window.open('nextstage.html');
return true;
}
}
I've done a dry run and found that the function only notices the first item in the index and ignores the others. I would be very grateful if anyone can highlight the error and suggest some alternatives. Thanks.