1

I have some form validation on my website.

If the account code field contains "XXX" and the reference field is blank, I want an alert to come up for the user to populate the reference field.

I have read that indexOf is the function I need, but the code below does not appear to work. Any ideas?

<SCRIPT>
if (form.account.value.indexOf("XXX") != -1 & form.reference.value == "") { 
   alert("Please Enter Reference Number"); 
   form.reference.focus( ); 
   return false; 
}
</script>
1
  • 2
    I think you meant && Commented Nov 19, 2015 at 15:59

1 Answer 1

1

Can you try:

if (form.account.value.indexOf("XXX") != -1 && form.reference.value == "") { 
   alert("Please Enter Reference Number"); 
   form.reference.focus( ); 
   return false; 
}

This corrects the AND clause, which uses && not &.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.