473,396 Members | 2,050 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,396 software developers and data experts.

getElementById help

I still not advanced at javascript and I am trying to do a picture portfolio
page where there is a scrollable area with thumbnails. When you click on the
thumbnail, I want to use document.getElementIDBy to change which picture is
displayed in the fullsize area. Everything seems right, but I keep getting
an error:

*Line: 3 | Error: Expected ';' *

I am kinda boggled because I clearly closed with * ; * If anyone could help,
or if there is a better way to do it, please let me know.

Here is the code that applies:

HTML: <div id="picdisplay"><table align="center" width="100%"
height="100%"><tr><td id="fullpicture" align="center"
valign="middle"></td></tr></table></div>

javascript: function one1() {
document.getElementById("fullpicture").innerHTML=" <img
src="images/portfolio/photo1.jpg" border="0" alt="One">";
}

actual page: http://members.shaw.ca/sceniclandscapes/portfolio.htm

In advance, Thanks a million!
Dave
Jul 23 '05 #1
3 2882
You've got double quotes in the javascript statement that are not escaped out.
Either use single quotes for the embedded parts:

document.getElementById("fullpicture").innerHTML=" <img
src='images/portfolio/photo1.jpg' border='0' alt='One'>";

or use the escape sequence:

document.getElementById("fullpicture").innerHTML=" <img
src=\"images/portfolio/photo1.jpg\" border=\"0\" alt=\"One\">";

I still not advanced at javascript and I am trying to do a picture portfolio
page where there is a scrollable area with thumbnails. When you click on the
thumbnail, I want to use document.getElementIDBy to change which picture is
displayed in the fullsize area. Everything seems right, but I keep getting
an error:

*Line: 3 | Error: Expected ';' *

I am kinda boggled because I clearly closed with * ; * If anyone could help,
or if there is a better way to do it, please let me know.

Here is the code that applies:

HTML: <div id="picdisplay"><table align="center" width="100%"
height="100%"><tr><td id="fullpicture" align="center"
valign="middle"></td></tr></table></div>

javascript: function one1() {
document.getElementById("fullpicture").innerHTML= "";
}

actual page: http://members.shaw.ca/sceniclandscapes/portfolio.htm

In advance, Thanks a million!
Dave

Jul 23 '05 #2
ChrisRath schrieb:
You've got double quotes in the javascript statement that are not escaped out.
Either use single quotes for the embedded parts:

document.getElementById("fullpicture").innerHTML=" <img
src='images/portfolio/photo1.jpg' border='0' alt='One'>";

or use the escape sequence:

document.getElementById("fullpicture").innerHTML=" <img
src=\"images/portfolio/photo1.jpg\" border=\"0\" alt=\"One\">";


Or

document.getElementById("fullpicture").innerHTML =
'<img src="images/portfolio/photo1.jpg" border="0" alt="One">';

However, this is a DOM mix known to be error-prone:
document.getElementById() is part of W3C DOM Level 1+.
The "innerHTML" property is part of proprietary DOMs.
Both should not be combined untested.

Instead, one should either use proprietary DOMs, in IE for example:

var o = document.all("fullpicture");
if (o && o.innerHTML)
{
o.innerHTML = ...
}

or the W3C DOM:

var o = document.getElementById("fullpicture");
if (o
&& typeof o.firstChild != "undefined"
&& typeof o.removeChild != "undefined"
&& typeof document.createElement != "undefined")
&& typeof o.appendChild != "undefined")
{
// remove all child elements
while (o.firstChild)
{
o.removeChild(o.firstChild);
}

// append "img" element as only child element
var o2 = document.createElement("img");
if (o2)
{
o2.src = "images/portfolio/photo1.jpg";
o2.border = "0";
o2.alt = "One";
o.appendChild(o2);
}
}

or test if a combination of both is supported by the UA
before it is used:

var o = document.getElementById("fullpicture");
if (o)
{
if (o.innerHTML)
{
o.innerHTML = ...;
}
else (if typeof o.firstChild != "undefined"
&& ...)
{
// see above
}
}

A DHTML library, such as <http://pointedears.de/scripts/dhtml.js>,
can provide for easy DOM scripting, selecting an adequate access
method for the respective UA using feature detection.
PointedEars
Jul 23 '05 #3
Thomas 'PointedEars' Lahn wrote:
ChrisRath schrieb: <snip> However, this is a DOM mix known to be error-prone:
document.getElementById() is part of W3C DOM Level 1+.
The "innerHTML" property is part of proprietary DOMs.
Both should not be combined untested.
Both should not be used untested, ever. But combining W3C with
proprietary DOM features is not any more error prone than browser
scripting in general. And given that browsers implement parts of both to
some extent, a pragmatic approach of using what is available (probably
preferring W3C DOM), when available, will tend to result in
cross-browser code with the largest base of actively supporting
browsers.

<snip> if (o
&& typeof o.firstChild != "undefined"
&& typeof o.removeChild != "undefined"
&& typeof document.createElement != "undefined")
&& typeof o.appendChild != "undefined")
{ <snip> if (o)
{
if (o.innerHTML)
{
o.innerHTML = ...;
}

<snip>

I don't really agree with using - typeof - to test properties of objects
that may be only objects/methods or undefined where a type-converting
test would produce the same results more efficiently, but testing -
innerHTML - really needs a - typeof - test because if it returns an
empty string you will get a false negative from a type-converting test.

Richard.
Jul 23 '05 #4

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

Similar topics

4
by: Michael Hill | last post by:
I have this tag: <span id="member_id"></span> and I want to change the value to "Member" why can't I do: document.getElementByID("member_id").value = "Member";
2
by: Gary Mayor | last post by:
Hi, I'm back again. Basically i'm trying to draw a box over an image which is turning out to be a nightmare. The problem i'm getting at the moment is that i'm creating a line with <div which works...
8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
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...
7
by: PaulB | last post by:
Good Morning everybody, I'm trying to adapt a tutorial script that will handle the behaviour of an "Expanding/Contracting" site-navigation menu. The code that seems to handle the expansion and...
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
2
by: New guy.. please help | last post by:
"New guy.. please help" wrote: Hi, I'm a new kid onthe block.. I have a small company with a website that was developed in .net by a company for me. I want to work on it myself so I installed...
1
by: Andre Ranieri | last post by:
Hello, I'm trying to set up an ASP.NET 2.0 form where the user enters values in WebControls.TextBoxes for amount owing, interest and late fees and a JavaScript function totals the three values...
4
by: Claudio Calboni | last post by:
Hello folks, I'm having some performance issues with the client-side part of my application. Basically, it renders a huge HTML table (about 20'000 cells in my testing scenario), without content....
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:
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
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?
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...
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.