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

dynamic element access / moz Y - ie N

Hello,

I want to access an element by passing part of the name to the function...

eg:

function show_files(item,data) {
document.getElementById('row-' + item).innerHTML = data;
}

show_files('2','hello world');

This seems to work fine in Firefox, but errors in IE. What is the best
way to dynamically access an element?

Cheers
-J
--
Jason Morehouse
Vendorama - Create your own online store
http://www.vendorama.com
Jul 23 '05 #1
2 1250
Jason Morehouse wrote:
Hello,

I want to access an element by passing part of the name to the function...
eg:

function show_files(item,data) {
document.getElementById('row-' + item).innerHTML = data;
}

show_files('2','hello world');

This seems to work fine in Firefox, but errors in IE. What is the best way to dynamically access an element?

Cheers
-J
--
Jason Morehouse
Vendorama - Create your own online store
http://www.vendorama.com


Works here. What was the error message?

Just fyi, 'item' is not the best choice for an identifier, as it's
already getting a serious workout as a method name, particularly in
MSIE.

If 'data' is purely textual (no markup) consider appending a text node
instead of using innerHTML.

Jul 23 '05 #2
Jason Morehouse wrote:
Hello,

I want to access an element by passing part of the name to the function...

eg:

function show_files(item,data) {
document.getElementById('row-' + item).innerHTML = data;
}

show_files('2','hello world');

This seems to work fine in Firefox, but errors in IE. What is the best
way to dynamically access an element?

Cheers
-J


It depends a bit on what "row-2" is. If it's a reference to a table
row, don't attempt to modify it using innerHTML:

"...you also cannot set InnerHtml on TABLE and TR elements, as
assigning malformed HTML to these elements could corrupt the
rendering of the document. Use AppendChild or the insertRow and
insertCell methods on the unmanaged IHTMLTable interface to add rows
and cells to a TABLE".
<URL:http://longhorn.msdn.microsoft.com/lhsdk/ref/ns/system.windows.forms/c/htmlelement/p/innerhtml.aspx>

Please take the advice on this page with a grain of salt, its suggested
use of innerText should be avoided unless you like IE-only code,
similarly for InsertAdjacentElement. Also note the erroneous use of
"innerHtml" rather than "innerHTML" - and they invented it!

innerHTML can be used to change the content of a cell or other element,
but not other parts of a table - though you can use it to change/create
an entire table, from <table ... to ...</table>.

--
Rob
Jul 23 '05 #3

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

Similar topics

11
by: fivelitermustang | last post by:
Actually, how would I go about allocating a four-dimensional dynamic array? I only know how to make two dimensional dynamic arrays: double **v; v = new double*; for (int i=0; i<C; i++) { v =...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
4
by: Excluded_Middle | last post by:
what is wrong with this code #include <stdio.h> typedef struct s1 { int a; int b; }s1;
4
by: Saul775 | last post by:
Hello, all: Just a general question that's been bothering me. Suppose I'd like to create a 2D array of integers -- not using the vector template -- but I need to dynamically create the array as...
22
by: Saul | last post by:
I have a set of radio buttons that are created dynamically, after rendered I try loop thru this set by getting the length of the set, but I keep getting an error stating the element is undefined. I...
2
by: rob.horvath | last post by:
Ok, I'm having what is most likely a very newbie problem, but... I am generating dynamic content for a page within a DIV on my main page (so I have a 'content' DIV). This works very well, and all...
2
by: czuvich | last post by:
All, I was wondering if it was possible to change a css class on a page load (somehow). Basically, I am wanting to say this: <div id="myclass" class="a javascriptfunction"> Is this...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
14
by: mojumbo | last post by:
Problem: I have a structure which needs to store its data in contiguous memory by there is a dynamic element which can't be defined at compile time. It needs to be aligned along a 4 byte...
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: 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: 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: 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
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,...

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.