getElementById problem on IE

Discussion in 'Javascript' started by jaapkramer@gmail.com, Jul 6, 2005.

  1. Guest

    I have this function which changes the image according to a selection
    which is made by a select box.

    This is all working great with Firefox and on a Mac. But it refuses to
    work in IE. In IE it will change the source, but the image isn't
    replaced (still get it?)
    So i change the source to order1.gif, but order0.gif is still
    displayed.

    <select name=\"prior22345\" class=\"noprint\"
    onChange=\"javascript:changePrior(22345)\" id=\"22345\">
    <option value=\"0\">0</option>
    <option value=\"1\">1</option>
    <option value=\"2\">2</option>
    <option value=\"3\">3</option>
    <option value=\"4\">4</option>
    <option value=\"5\">5</option>
    <option value=\"6\">6</option>
    <option value=\"7\">7</option>
    <option value=\"8\">8</option>
    </select>

    this is the image i'm changing:

    <img src='images/icons/order0.gif' id='prior22345'>

    the function i'm executing:

    function changePrior( waid )
    {
    prioriteit = document.getElementById( waid ).value;
    document.getElementById('prior'+ waid).src = 'images/icons/order' +
    prioriteit + '.gif';
    checker();
    }
    \
     
    , Jul 6, 2005
    #1
    1. Advertising

  2. Guest

    I probably found the problem.
    I have a form around the image and select box. If i remove it the
    function is working great.

    But i can't remove the form tags because other functions will stop
    working instead. Is theire a way around my problem?
     
    , Jul 6, 2005
    #2
    1. Advertising

  3. Guest

    You are right, stupid that i didn't noticed that. Ohwell, most faults
    are stupid ones.

    Thank You for helping me out.
     
    , Jul 6, 2005
    #3
  4. Grant Wagner Guest

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    "Duncan Booth" <> wrote in message
    news:Xns968B80ADFE10Bduncanbooth@127.0.0.1...
    > wrote:
    >
    > Have you heard of the 'cardboard programmer' technique? Get a
    > life-size
    > cardboard cut-out of another programmer (a stuffed toy, pot plant, or
    > in
    > emergencies a live human with no programming abilities will do equally
    > well), and explain to it in great detail exactly why it is your code
    > can't
    > possibly be failing. Almost invariably part way through the
    > explanation
    > you'll find the answer.


    Variations on a theme:

    http://www.sellsbrothers.com/spout/default.aspx?content=archive.htm#teddybear

    "According to legend, the TA office next to the Stanford computer
    science lab is guarded by a teddy bear. Before a student is allowed to
    consume valuable time asking a question of the TA, they must first
    explain it to the teddy bear. Apparently the bear is able to answer 80%
    of the questions that students ask, saving time for the TAs to play
    Unreal Tournament."

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Grant Wagner, Jul 8, 2005
    #4
  5. wrote:

    > <select name=\"prior22345\" class=\"noprint\"

    ^^ ^^ ^^ ^^
    > onChange=\"javascript:changePrior(22345)\" id=\"22345\">

    ^^ ^^ ^^ ^^
    > <option value=\"0\">0</option>

    ^^ ^^
    > <option value=\"1\">1</option>

    ^^ ^^
    > <option value=\"2\">2</option>

    ^^ ^^
    > <option value=\"3\">3</option>

    ^^ ^^
    > <option value=\"4\">4</option>

    ^^ ^^
    > <option value=\"5\">5</option>

    ^^ ^^
    > <option value=\"6\">6</option>

    ^^ ^^
    > <option value=\"7\">7</option>

    ^^ ^^
    > <option value=\"8\">8</option>

    ^^ ^^
    > </select>


    How do you got the idea that you should escape
    attribute value delimiters when used as such?

    > this is the image i'm changing:
    >
    > <img src='images/icons/order0.gif' id='prior22345'>


    That `img' element lacks the mandatory `alt' attribute.

    <http://validator.w3.org/>

    > the function i'm executing:
    >
    > function changePrior( waid )
    > {
    > prioriteit = document.getElementById( waid ).value;
    > document.getElementById('prior'+ waid).src = 'images/icons/order' +
    > prioriteit + '.gif';


    Use collections instead:

    var e, prioriteit =
    (e = document.forms[...].elements['prior' + waid])
    .options[e.selectedIndex].value;

    document.images['prior' + waid].src =
    'images/icons/order' + prioriteit + '.gif';

    This way you also work around issues with namespaces.

    Don't use `javascript:' URIs in event handler attribute values but
    declare the default scripting language instead using a `meta' element.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jul 17, 2005
    #5
    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. Skeets
    Replies:
    4
    Views:
    6,039
    Skeets
    Feb 23, 2006
  2. TR
    Replies:
    5
    Views:
    132
    Richard Cornford
    May 19, 2004
  3. JKD

    getElementById problem

    JKD, Dec 1, 2004, in forum: Javascript
    Replies:
    3
    Views:
    103
  4. Michael Winter

    getelementbyid problem

    Michael Winter, Apr 16, 2005, in forum: Javascript
    Replies:
    1
    Views:
    112
    Warren Thai
    Apr 17, 2005
  5. Robi
    Replies:
    12
    Views:
    149
    tsar bob
    Aug 3, 2005
Loading...

Share This Page