/    Sign up×
Community /Pin to ProfileBookmark

New here – help with image change and dropdown

I know enough JS just to screw things up, apparent by this post. ?

I am trying to create an order form for cutom purses, totes, etc. I have drop down boxes with the name of fabrics, ribbons, etc. and when a custom selects a name, I want an image to the left of the dropdown to change to the correct swatch.

Here is what I have so far — where did I go wrong?

[QUOTE]

<script language=”JavaScript” type=”text/JavaScript”>
<!–
function UpdateColor() {
colors = new Array(2);
colors[16]=”cordgrey_t.jpg”;
colors[17]=”cordolive_t.jpg”;
index = document.add.OPTidOption7.selectedIndex;
document.add.color.src=”images/”+colors[index];
}
//–>
</script>

[/QUOTE]

and for the images/dropdown I have

[QUOTE]

<img src=”images/cordgrey_t.jpg” border=”1″ id=”color”>

<select name=”OPTidOption7″ class=”CPoptSel” onChange=”javascript:UpdateColor()”>
<option value=”16″>Corduroy : Grey</option>
<option value=”17″>Corduroy : Olive</option>
</select>

[/QUOTE]

Any help is SO appreciated!!!!!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@herodote92Feb 27.2005 — <i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
function UpdateColor() {
colors = new Array();
colors[16]="cordgrey_t.jpg";
colors[17]="cordolive_t.jpg";
var my_sel = document.getElementsByName("OPTidOption7")[0];
document.getElementById("mycolor").src = colors[my_sel[my_sel.selectedIndex].value];
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;img src="cordgrey_t.jpg" border="1" id="mycolor"&gt;

&lt;select name="OPTidOption7" onchange="UpdateColor();"&gt;
&lt;option value="16" selected&gt;Corduroy : Grey&lt;/option&gt;
&lt;option value="17"&gt;Corduroy : Olive&lt;/option&gt;
&lt;/select&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @savvymedias 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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