/    Sign up×
Community /Pin to ProfileBookmark

forms properties

I’m trying to make a dynamic menu using javascript but I keep getting an error message saying that document.myform has no properties. I can’t see any problems myself. I’m not very good with javascript. Here is my code, could you please look at it and tell me if you see a problem?
Thanks
<html>
<head>
<script>

function changemenu()
{

for ( i=1; i<Rock.length; i++)
{
document.myform.myselect.options[i] = menu[i];
}

for ( i=2; i<Metal.length; i++)
{
document.myform.myselect.options[i] = menu[i];
}

for ( i= 3; i<Indie.length; i++)
{
document.myform.myselect.options[i] = menu[i];
}
}

document.myform.myselect.options[1] = new Option (“Rock”, “1”);document.myform.myselect.options[2] = new Option (“Metal”, “2”);
document.myform.myselect.options[3] = new Option (“Indie”, “3”);
var Metal = new Array();

Metal [1] = new Option (“Metallica”, “artist1”);
Metal [2] = new Option (“SystemOfADown”, “artist2”);

var Indie = new Array();

Indie [1] = new Option (“DamienRice”, “artist1”);
Indie [2] = new Option (“SnowPatrol”, “artist2”);

var Rock = new Array();

Rock [1] = new Option (“Incubus”, “artist1”);
Rock [2] = new Option (“Pearl Jam”, “artist2”);
</script>
</head>
<body>
<form name = “myform”>

<table cellpadding=10>
<tr>
<td><p><select name=”myselect”>
<option selected>genre </option>
<option> Rock </option>
<option> Metal </option>
<option> Indie </option>
</select>
</p>
</td>
<td>
<p><select>
<option selected>artist</select>
<option value = “artist1” > </option>
<option value = “artist2” > </option>
</select>
</p>
</td>
<td>
<p><select>
<option selected>Album</select>
<option value = “album1”></option>
<option value=”album2″></option>
<option value=”album3″></option>
</select>
</p>
</td>
</tr>
</table>
</form>

</body>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@yellabuffDec 19.2006 — document.myform.myselect.options[1] = new Option ("Rock", "1");document.myform.myselect.options[2] = new Option ("Metal", "2");

This line is attempting to be executed before the form has even loaded. That's why you are getting that error.
×

Success!

Help @Emmajane 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.19,
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,
)...