select in form

T

twopeak

Hello

I'm making a script, that should allow users to change a select box, and
this changes the alt and the src of several images.

I have made a script (see under) that exactly does what it's supposed to do!
My problem is that this was just a page to test,
now I'm implementing it in my page
And as soon as the select box is inside the form, when I change the select I
get an error "this object doesn't support this property"

When the document loads, the javascript function gets triggered a first time
without a problem, so the error has to be something about the
<select name="set" onChange="verander(this.value)">

what am I doing wrong?

thanks for all help

Code:

<html><head></head><body>


<html><head><title>javascript</title></head><body>
<script language="javascript">

function addsmile(image_name) {
var smiley;
smiley = document.images[image_name].alt;
doc_content = document.gb.elements['bericht'].value + smiley;
document.gb.elements['bericht'].value = doc_content;
document.gb.elements['bericht'].focus();
}


function verander(set) {
var sources = new Array(10);
var alttags = new Array(10);
if (set == 'set1') {
sources[1] = /smileys/blu4.gif'; alttags[1] = ' (cactus)';
sources[2] = /smileys/blume5.gif'; alttags[2] = ' @-\'-,-';
sources[3] = /smileys/blume5.gif'; alttags[3] = ' (roos)';
sources[4] = /smileys/booze.gif'; alttags[4] = ' (alkol)';
sources[5] = /smileys/freak.gif'; alttags[5] = ' (freak)';
} else if (set == 'set2') {
sources[1] = /smileys/partyf.gif'; alttags[1] = ' (punk)';
sources[2] = /smileys/perfect.gif'; alttags[2] = ' (y)';
sources[3] = /smileys/puke.gif'; alttags[3] = ' :#';
sources[4] = /smileys/puke.gif'; alttags[4] = ' :-#';
sources[5] = /smileys/slet.gif'; alttags[5] = ' (slet)';
} else if (set == 'set3') {
sources[1] = /smileys/smoke.gif'; alttags[1] = ' :-Q';
sources[2] = /smileys/worshippy.gif'; alttags[2] = ' <<:)>>';
sources[3] = /smileys/superman.gif'; alttags[3] = ' (reno)';
sources[4] = /smileys/mario.gif'; alttags[4] = ' (gio)';
sources[5] = /smileys/cartman.gif'; alttags[5] = ' (cartman)';
}
var begin = "";
document.images['een'].src = begin + sources[1]; document.images['een'].alt
= alttags[1];
document.images['twee'].src = begin + sources[2];
document.images['twee'].alt = alttags[2];
document.images['drie'].src = begin + sources[3];
document.images['drie'].alt = alttags[3];
document.images['vier'].src = begin + sources[4];
document.images['vier'].alt = alttags[4];
document.images['vijf'].src = begin + sources[5];
document.images['vijf'].alt = alttags[5];
}

</script>
</head><body onLoad="verander('set1')">
<select name="verander" onChange="verander(this.value);">
<option value="set1">set1</option><option value="set2">set2</option><option
value="set3">set3</option><option value="set4">set4</option><option
value="set5">set5</option><option value="set6">set6</option><option
value="set7">set7</option><option value="set8">set8</option><option
value="set9">set9</option><option value="set10">set10</option><option
value="set11">set11</option><option value="set12">set12</option><option
value="set13">set13</option><option value="set14">set14</option><option
value="set15">set15</option><option value="set16">set16</option> </select>
<form name="gb" action="test.html" method="post">
<a href="Javascript:addsmile('een')"> <img name="een" src="" alt=""
border="0" height="32"></a> &nbsp;
<a href="Javascript:addsmile('twee')"> <img name="twee" src="" alt=""
border="0" height="32"></a> &nbsp;
<a href="Javascript:addsmile('drie')"> <img name="drie" src="" alt=""
border="0" height="32"></a> &nbsp;
<a href="Javascript:addsmile('vier')"> <img name="vier" src="" alt=""
border="0" height="32"></a> &nbsp;
<a href="Javascript:addsmile('vijf')"> <img name="vijf" src="" alt=""
border="0" height="32"></a> &nbsp;
<br>
<textarea name="bericht" rows="10" cols="30"></textarea><br>
</form>
</p>
</body>
</html>
 
J

Janwillem Borleffs

twopeak said:
When the document loads, the javascript function gets triggered a first time
without a problem, so the error has to be something about the
<select name="set" onChange="verander(this.value)">

what am I doing wrong?

if (set == 'set1') {
sources[1] = /smileys/blu4.gif'; alttags[1] = ' (cactus)';

You are missing out on the quotes. Per example, the line above should read:

sources[1] = '/smileys/blu4.gif'; alttags[1] = ' (cactus)';


JW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top