Reputation: 21
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
Reputation:
You also have while(i<=mine.length)
shouldn't it be while(i < mine.length)
Upvotes: 0
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