/    Sign up×
Community /Pin to ProfileBookmark

Javascript error: Object Expected Line 54

I’ve posted the function which is in the the head between <script> tags. And I’ve posted the line in the body which references the function. Line 54 is the <input> line. I’m just trying to check the values of the array and I keep getting the error Object Expected. Any help is appreciated… Thanks.

Legion

function abcd()
{
for (var i=1; i<23; i++)
alert(regionarray[i]);
}

<body>
<form name=”theform”>
<input name=”thetext” type=”text” id=”Q5A” size=”59″ maxlength=”255″ onClick=”JavaScript: abcd();”>
</form>
</body>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@ExuroMay 27.2004 — is the abcd() function the only one on your page? If not, you may be missing a } or something...
Copy linkTweet thisAlerts:
@legionbaauthorMay 27.2004 — above the function I have the following assignments.

var regionarray = New Array(23);

regionarray[1]="Alberta"

regionarray[2]="Alberta"

regionarray[3]="Atlantic"

regionarray[4]="Atlantic"

regionarray[5]="BC"

regionarray[6]="BC & Northern"

regionarray[7]="BC-1"

regionarray[8]="BC-4"

regionarray[9]="Central Canada"

regionarray[10]="Eastern Canada"

regionarray[11]="GTA"

regionarray[12]="GTA Central"

regionarray[13]="GTA East"

regionarray[14]="GTA West"

regionarray[15]="National"

regionarray[16]="National"

regionarray[17]="OEN"

regionarray[18]="Ontario"

regionarray[19]="Ontario"

regionarray[20]="OSW"

regionarray[21]="Praries"

regionarray[22]="Quebec"

regionarray[23]="Quebec"

When I remove those lines, the error disappears.
Copy linkTweet thisAlerts:
@TheBearMayMay 27.2004 — Well, it may be nothing, but JS arrays start at 0, so by requesting an array of 23 items your index should run from 0-22. Thus, regionarray[23]="Quebec" is invalid.
Copy linkTweet thisAlerts:
@legionbaauthorMay 27.2004 — Just so things are a little clearer. Here's the file as it is now. I know the error has something to do with the array. I'm not sure what though. I'm relatively unfamiliar with JavaScript. The error I get is Object Expected. It goes away if I eliminate the array.

<html>

<head>

<title></title>

<style type="text/css">

<!--

.ArialText {

font-family: Arial, Helvetica, sans-serif;

font-size: 10pt;

font-style: normal;

line-height: normal;

font-weight: normal;

font-variant: normal;

color: #000000;

}

-->

</style>

<script language="JavaScript">

var regionarray = New Array();

regionarray[0]=new Array('Alberta');

regionarray[1]=new Array('Alberta');

regionarray[2]=new Array('Atlantic');

regionarray[3]=new Array('Atlantic');

regionarray[4]=new Array('BC');

regionarray[5]=new Array('BC & Northern');

regionarray[6]=new Array('BC-1');

regionarray[7]=new Array('BC-4');

regionarray[8]=new Array('Central Canada');

regionarray[9]=new Array('Eastern Canada');

regionarray[10]=new Array('GTA');

regionarray[11]=new Array('GTA Central');

regionarray[12]=new Array('GTA East');

regionarray[13]=new Array('GTA West');

regionarray[14]=new Array('National');

regionarray[15]=new Array('National');

regionarray[16]=new Array('OEN');

regionarray[17]=new Array('Ontario');

regionarray[18]=new Array('Ontario');

regionarray[19]=new Array('OSW');

regionarray[20]=new Array('Praries');

regionarray[21]=new Array('Quebec');

regionarray[22]=new Array('Quebec');


function onSegListChange()

{

alert('segment');

}

</script>

</head>

<body>

<form name="SurveyForm">

<select name="Month" id="Month" onChange="onSegListChange()">

<option value="0" selected>Month</option>

<option value="January">Jan</option>

<option value="February">Feb</option>

<option value="March">Mar</option>

<option value="April">Apr</option>

<option value="May">May</option>

<option value="June">Jun</option>

<option value="July">Jul</option>

<option value="August">Aug</option>

<option value="September">Sept</option>

<option value="October">Oct</option>

<option value="November">Nov</option>

<option value="December">Dec</option>

</select>

<input name="action" type="hidden" value="">

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@TheBearMayMay 27.2004 — Try making New new, i.e.

var regionarray = New Array();

should be

var regionarray = new Array();
Copy linkTweet thisAlerts:
@legionbaauthorMay 27.2004 — Dude... thank you... thank you so much. Who knew a capital N could cause 4 hours of grief.
×

Success!

Help @legionba spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...