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

Problem with document.getElementById

I am writing a pretty simple Javascript which makes use of getElementById to work with some divs on the page.

The divs are labelled correctly (id="whatever") and there are no duplicate div ids.

I have tried addressing the divs using:

document.getElementById("whatever") as well as
document.getElementById('whatever')

In all cases, I am getting nothing but a null value returned.

I'm using the XHTML Transitional 1.1 doctype and am seeing this problem occur on all testing browsers. I have validated the HTML of the page and it's fine.

I've even used Firefox to display all divs on the page, and they are all showing up exactly as coded.

Any suggestions?

-- Gary
Dec 5 '06 #1
4 1822
iam_clint
1,208 Expert 1GB
well with just getting the element all your are getting is the object what are you trying todo with the divs
Dec 5 '06 #2
AricC
1,892 Expert 1GB
Post the code that isn't working I'm sure we'll be able to spot an error like this immediately.
Dec 5 '06 #3
Hi,

I posted copies of all the relevant files at:

http://demo.encoremarketing.com/tests/speigel.html

For the Javascript, I created just a simple script that would grab the id of a div that I knew exists in the code and put it in an alert statement, just so that I could figure out what I am doing wrong. But the alert always says "null"

Thanks for all your help folks.
Dec 6 '06 #4
AricC
1,892 Expert 1GB
Not sure what's going on but this works:

[html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test Get Element By ID</title>

<script type="text/javascript">

function Something()
{
var Navigation = document.getElementById("navigation")

alert(navigation.innerHTML)

}

</script>


</head>

<body onload="Something();">

<div id="navigation">
<ul id="navmenu">
<li><a href="/content/index.cfm?cID=1645" target="_self">Great Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Great Deals" /></a>
<ul>
<li><a href="/content/index.cfm?cID=1646" target="_self">Great Deal 1</a></li>
<li><a href="/content/index.cfm?cID=1652" target="_self">Long content</a></li>
<li><a href="/content/index.cfm?cID=1651" target="_self">Signup Page</a></li>
</ul>
</li>
<li><a href="/content/index.cfm?cID=1647" target="_self">More Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="More Deals" /></a>
<ul>
<li><a href="/content/index.cfm?cID=1648" target="_self">Info page</a></li>
<li><a href="/content/index.cfm?cID=1649" target="_self">Test frame</a></li>
<li><a href="/content/index.cfm?cID=1650" target="_self">Test frame 2</a></li>
</ul>
</li>
<li><a href="/content/index.cfm?cID=1653" target="_self">Fun Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Fun Deals" /></a>
<ul>
<li><a href="/content/index.cfm?cID=1657" target="_self">Page 1</a></li>
</ul>
</li>
<li><a href="/content/index.cfm?cID=1654" target="_self">Hot Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Hot Deals" /></a>
<ul>
<li><a href="/content/index.cfm?cID=1658" target="_self">Page 1</a></li>
</ul>
</li>
<li><a href="/content/index.cfm?cID=1655" target="_self">Cool Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Cool Deals" /></a>
<ul>
<li><a href="/content/index.cfm?cID=1659" target="_self">Page 1</a></li>
</ul>
</li>
<li><a href="/content/index.cfm?cID=1656" target="_self">Latest Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Latest Deals" /></a>
<ul>
<li><a href="/content/index.cfm?cID=1660" target="_self">Page 1</a></li>
</ul>
</li>
</ul>
</div>




</body>


</html>
[/html]
Dec 6 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Bryan | last post by:
I am attempting to make a web page more Netscape friendly... <a href="http:www.gordonceilings.com"></a> I have already corrected the table issues in an offline staging site (where I do the...
4
by: tcole6 | last post by:
My problem appears to be Firefox specific. I have a hyperlink that loads a new window. This window contains hyperlinks that call javascript functions in the parent window and then closes the...
2
by: K. | last post by:
Hello! I have the following problem. I have form div which is replaced by ajax event. Unofrtunately all the ajax inputs are null after posting the form (method="post") in Firefox, but on...
15
by: cssExp | last post by:
hello, Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
2
by: stevemtno | last post by:
I've got a problem with a web page I'm working on. I have 4 modules - one of them has 2 tabs, two of them have 4 tabs. When the user clicks on the tabs, the content below them changes. However, when...
7
by: raknin | last post by:
Hi I have a carousel script. I want to load the carousel with a new set of pictures every time I press a button. The problem that I have that the script append the new pictures to the olds one...
23
by: andersond | last post by:
I have a form with 31 questions each of which could cause an application to be rejected. I have 10 fields named issue 1...issue10. If a problem is found I want to save a message to the first empty...
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
2
by: swethak | last post by:
Hi, i am getting the problem when i used the onclick event in option tag.It is working fine in mozilla .But it is not working IE. Here is my code <script>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.