Faith Camille
Faith Camille

Reputation: 21

Javascript error: function expected

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++;
        }   
     }
}`

Upvotes: 1

Views: 13313

Answers (2)

user416527
user416527

Reputation:

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

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

Upvotes: 0

Sean Vieira
Sean Vieira

Reputation: 160043

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).

Upvotes: 6

Related Questions