/    Sign up×
Community /Pin to ProfileBookmark

JavaScript/Select Form help

I’m really stuck. What I’m trying to do is have a drop down list of courses for a given term. Below the 5 selection lists is 5 default images. When a course is chosen, I’d like the corresponding image to change to show that course’s information. I don’t want to write a function for each drop down, but have one function to handle all 5 changes.

This is the function that writes the selection list to the page…

function writeFall1() {
document.write(‘<select name=”year1fall”‘ + year1FallCourses + ‘ onChange=”stuff here>’);
document.write(‘<option>Choose a course…</option>’);
//start the filtering of all the CIS courses available for this term
for (i = 0; i < courseList.length; ++i) {
if ( courseList[i].f == “y” ) {
document.write(‘<option value=’ + courseList[i].id + ‘>’ + courseList[i].id + ‘ </option>’);
document.write(courseList[i].id + ” ” + courseList[i].title);
}
}
document.write(‘</select> &nbsp; &nbsp; &nbsp; &nbsp;’);
//increase this variable so that each selection box corresponds to one image field
year1FallCourses++;

}

This is the attempted image change function, just writing to the site to see what values i’m getting…

function changeImage(courseID, formID) {
document.write(courseID + ” ” + formID);
document.write(document.year1fall1.options);
}

If it helps, the html for this…
<img name=”year1fall1″ src=”images/default.jpg”>
<img name=”year1winter1″ src=”images/default.jpg”>
<img name=”year1spring1″ src=”images/default.jpg”>
<img name=”year2fall1″ src=”images/default.jpg”>
<img name=”year2winter1″ src=”images/default.jpg”>
<img name=”year2spring1″ src=”images/default.jpg”>

… so those appear horizontally. Going down, its “year1fall2”, “year1fall3” etc. to differentiate between the course selections.

It feels like i’m so close! Any help is much appreciated!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Dr_Huxtable 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...