473,394 Members | 1,718 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,394 software developers and data experts.

Small Javascript Question


Hi,

I have a form which puts out a hidden DIV like this:
<DIV id='invalid' style="display:none"><img src="../images/
flyer.jpg"></DIV>

So, the DIV is hidden until the customer performs some actions. Once
they do, I make the DIV appear like this:

document.getElementsByName('custphoto')[0].style.display="";

That works fine in IE. But Firefox gives this error:

Error: document.getElementsByName("custphoto")[0] has no properties

Why does that not work in Firefox, but does in IE? Can I make it
work in both browsers???

Thank you!
Jun 27 '08 #1
1 934
On May 12, 12:02 pm, Mtek <m...@mtekusa.comwrote:
Hi,

I have a form which puts out a hidden DIV like this:

<DIV id='invalid' style="display:none"><img src="../images/
flyer.jpg"></DIV>

So, the DIV is hidden until the customer performs some actions. Once
they do, I make the DIV appear like this:

document.getElementsByName('custphoto')[0].style.display="";
Presumably that is a typo and you mean 'invalid' not 'custphoto'.

That works fine in IE. But Firefox gives this error:

Error: document.getElementsByName("custphoto")[0] has no properties

Why does that not work in Firefox, but does in IE?
Two good reasons:

1. IE does not understand that name and ID attributes are
actually different attributes

2. the div doesn't have a name attribute, it has an ID.
getElementsByName should get elements with the same name
attribute value, not elements with the same ID attribute
value

and one more for good measure:

3. A Div element in an HTML document is not specified as
having a name attribute, therefore you should not expect
getElementsByName (which belongs to the DOM HTML spec) to work.

Can I make it work in both browsers???
You can make it work in any browser that supports DOM 1 (which is
pretty much any browser released in the last 8 years or so) by using
getElementById:

document.getElementById('invalid').style.display = '';
--
Rob
Jun 27 '08 #2

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

Similar topics

7
by: Sharon | last post by:
Hiya I have a small question, I saw this piece of code somewhere (it's for creating a customized context menu) and I was wondering: Why is it that the STYLE and SCRIPT-tags are broken up into...
8
by: handersonVA | last post by:
Hello, I'd like to put small images around a big image, so when a small image is clicked, that image is shown as a big image in the center. how should I do that? I will use a table tag to organize...
7
by: Tim Rogers | last post by:
Hi folks, this is a resolution-detect script that I used on a site. As you can see it is designed to detect when the screen resolution falls below a certain level then load an alternative style...
1
by: gkellymail | last post by:
I have a small javascript/html code below that demonstrates that problem I'm having in a larger program. I've tried all kinds of things to get it to work, but it just won't do what I want. I've...
4
by: ATS16805 | last post by:
Hi. I wonder if it's possible to "force" a browser to "switch to SSR mode" for any given document. Specifically, I'm looking for a solution, not to a User Agent issue (i think), but a coding idea;...
1
by: HACKhalo2 | last post by:
Hello. I want to make a PHP button that's small. Problem is, all my attempts either screwed up the layout or needed MUCH more code than i want to do. The page I'm using is set up with tables, if that...
6
by: Mark B | last post by:
I'd like a little window to pop up when a user clicks the hyperlink text "Grade Key": Grade Key Score Range A+ 95% - 100% A 90% - 94%...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.