select in form

Discussion in 'Javascript' started by twopeak, Aug 31, 2003.

  1. twopeak

    twopeak Guest

    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>
    twopeak, Aug 31, 2003
    #1
    1. Advertising

  2. "twopeak" <> schreef in bericht
    news:mkt4b.11918$-ops.be...
    >
    > 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
    Janwillem Borleffs, Aug 31, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFiYmxlcg==?=

    select gridview row without using select button?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 3, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    101,478
    dch31969
    Feb 27, 2009
  2. J. Hall
    Replies:
    2
    Views:
    985
    Jeff Thies
    Apr 21, 2004
  3. jas

    select.select() on windows

    jas, Oct 25, 2005, in forum: Python
    Replies:
    4
    Views:
    767
    Maksim Kasimov
    Oct 27, 2005
  4. yawnmoth
    Replies:
    2
    Views:
    432
    Peter Flynn
    Aug 18, 2008
  5. palmiere
    Replies:
    1
    Views:
    313
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page