I'm trying to validate a form using javascript. Checking to see if the input value matches any value within an array before returning true.
Here's an example of what I have written so far. Yet this seems to not work.
<script type='text/javascript'>
function checkForm()
{
var agent = document.getElementById('agent').value;
var myArray = new Array()
myArray[0] = 'First Agent';
myArray[1] = 'Second Agent';
myArray[2] = 'Third Agent';
if (agent != myArray)
{
alert("Invalid Agent");
return false;
}
else
{
return true;
}
}
<form>
<fieldset>
Agents Name*
<input type="text" size="20" name="agent" id="agent">
</fieldset>
</form>