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++;
}
}
}`
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++;
}
}
}`
Share
Improve this question
asked Aug 14, 2012 at 5:45
Faith CamilleFaith Camille
211 gold badge1 silver badge6 bronze badges
0
2 Answers
Reset to default 6mine
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).
You also have while(i<=mine.length)
shouldn't it be while(i < mine.length)