473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

getElementById problem on IE

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 23 '05 #1
6 1604
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 23 '05 #2
wrote:
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?


Your select tag has a 'name' attribute which is the same as the img tag's
'id'. IE pollutes the 'id' namespace with the 'name' attributes from form
controls, so I guess you are picking up the select tag instead of the
image. Change the id on the image and it should work fine.
Jul 23 '05 #3
You are right, stupid that i didn't noticed that. Ohwell, most faults
are stupid ones.

Thank You for helping me out.

Jul 23 '05 #4
wrote:
You are right, stupid that i didn't noticed that. Ohwell, most faults
are stupid ones.
It is always easier to spot that kind of mistake when you are trying to
figure out what the code does than when you think you already know what it
does.

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.

Thank You for helping me out.

Glad to help.
Jul 23 '05 #5


--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
"Duncan Booth" <du**********@invalid.invalid> wrote in message
news:Xn*************************@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/d....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 <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
ja********@gmail.com 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
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
5
by: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.