1

I have this javascript and I get the error "function expected". I can't see anything wrong with my javascript. Please help. Thanks.

function checkrewardname()
{
var my=document.getElementById("Rname");
var con=my.value;
 var mine=document.getElementById("forref").value.split('\n');

if (con == "")
        {
            alert("Enter a Reward Name.");
    }
 else
    { 
    var i=0;
    while(i<=mine.length)
         {
            if (mine(i) == con)//error here
                {
                    alert("Duplicate reward. Please enter a new reward.");
                }
            else
                {
                    document.getElementById("validate").click();
                    alert("The reward has been saved.");
                }
            i++;
        }   
     }
}`
0

2 Answers 2

6

mine is an array but you are calling it as if it were a function. Use mine[i] rather than mine(i) and you'll access the array by index rather than generating an error. (Just a note; most C-style languages use [ and ] for array access and reserve ( and ) for function invocation).

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

Comments

0

You also have while(i<=mine.length)

shouldn't it be while(i < mine.length)

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.