Hello,
Would appreciate a little help here!
How do I refer to multiple elements with IDs such as question1,
question2, question3 etc, in following?
document.getElementById('question').innerHTML
I want to use
for (var num=1;num<6;num++) {
document.getElementById('question').innerHTML
}
but cannot work out how to get the question1, question2, etc into the
code...
Thanks
Geoff 10 1612
"Geoff Cox" <ge*******@notquitecorrectfreeuk.com> wrote in message
news:nv********************************@4ax.com... Hello,
Would appreciate a little help here!
How do I refer to multiple elements with IDs such as question1, question2, question3 etc, in following?
document.getElementById('question').innerHTML
I want to use
for (var num=1;num<6;num++) { document.getElementById('question').innerHTML }
but cannot work out how to get the question1, question2, etc into the code...
Thanks
Geoff
Try
for (var num=1;num<6;num++) {
document.getElementById('question'+num).innerHTML
}
On Tue, 11 Oct 2005 15:04:33 -0500, "McKirahan" <Ne**@McKirahan.com>
wrote: Try
for (var num=1;num<6;num++) { document.getElementById('question'+num).innerHTML }
Thanks for your reply - but I had tried the above - I get
document.getElementById(..] is null or not an object.
Any other thoughts?!
Cheers
Geoff
Geoff Cox wrote on 11 okt 2005 in comp.lang.javascript : On Tue, 11 Oct 2005 15:04:33 -0500, "McKirahan" <Ne**@McKirahan.com> wrote:
Try
for (var num=1;num<6;num++) { document.getElementById('question'+num).innerHTML } Thanks for your reply - but I had tried the above - I get
document.getElementById(..] is null or not an object.
You would, if you forget to id them correctly
<div id='question1' ...
<div id='question2' ...
<div id='question3' ...
<div id='question4' ...
<div id='question5' ...
Any other thoughts?!
why?
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Geoff Cox said: Hello,
Would appreciate a little help here!
How do I refer to multiple elements with IDs such as question1, question2, question3 etc, in following?
document.getElementById('question').innerHTML
I want to use
for (var num=1;num<6;num++) { document.getElementById('question').innerHTML }
but cannot work out how to get the question1, question2, etc into the code...
This is extremely basic Javascript. PLEASE find a manual or tutorial.
"question"+num
On 11 Oct 2005 20:21:00 GMT, "Evertjan."
<ex**************@interxnl.net> wrote: Geoff Cox wrote on 11 okt 2005 in comp.lang.javascript:
On Tue, 11 Oct 2005 15:04:33 -0500, "McKirahan" <Ne**@McKirahan.com> wrote:
Try
for (var num=1;num<6;num++) { document.getElementById('question'+num).innerHTML }
Thanks for your reply - but I had tried the above - I get
document.getElementById(..] is null or not an object.
You would, if you forget to id them correctly
<div id='question1' ... <div id='question2' ... <div id='question3' ... <div id='question4' ... <div id='question5' ...
well - I have for example,
<td ID='question4' width='30%' valign='top' height='70'></td>
so that should be OK ?
Geoff
Geoff Cox wrote on 11 okt 2005 in comp.lang.javascript : On 11 Oct 2005 20:21:00 GMT, "Evertjan." <ex**************@interxnl.net> wrote:
Geoff Cox wrote on 11 okt 2005 in comp.lang.javascript:
On Tue, 11 Oct 2005 15:04:33 -0500, "McKirahan" <Ne**@McKirahan.com> wrote:
Try
for (var num=1;num<6;num++) { document.getElementById('question'+num).innerHTML }
Thanks for your reply - but I had tried the above - I get
document.getElementById(..] is null or not an object.
You would, if you forget to id them correctly
<div id='question1' ... <div id='question2' ... <div id='question3' ... <div id='question4' ... <div id='question5' ...
well - I have for example,
<td ID='question4' width='30%' valign='top' height='70'></td>
so that should be OK ?
sure, but:
you will have tot test this for yourself in a simple setting,
and notin your seemingly productionready code, where you can make too
many mistakes.
first try my <div example for yourself
then start leaving out
width='30%' valign='top' height='70'
[which should be exchanged with css style,but that is another chapter]
or build a real simple test table
In general first make yourself at home with new [for you, seemingly]
concepts before applying them in a codewize real life situation.
Then your question "should this be OK" should not rize.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
On 11 Oct 2005 20:21:00 GMT, "Evertjan."
<ex**************@interxnl.net> wrote:
have sorted it out - the problem was not with the
document.getElementById('question' + num).innerHTML
but with an index mismatch in that the element IDs started with
question1 (ie 1) but the related array for the text started with 0 and
I was using the same num variable for both....
apologies for wasting your time.
Cheers
Geoff
Geoff Cox a écrit : On 11 Oct 2005 20:21:00 GMT, "Evertjan." <ex**************@interxnl.net> wrote:
Geoff Cox wrote on 11 okt 2005 in comp.lang.javascript:
On Tue, 11 Oct 2005 15:04:33 -0500, "McKirahan" <Ne**@McKirahan.com> wrote:
Try
for (var num=1;num<6;num++) { document.getElementById('question'+num).innerHTML }
Thanks for your reply - but I had tried the above - I get
document.getElementById(..] is null or not an object.
You would, if you forget to id them correctly
<div id='question1' ... <div id='question2' ... <div id='question3' ... <div id='question4' ... <div id='question5' ...
well - I have for example,
<td ID='question4' width='30%' valign='top' height='70'></td>
so that should be OK ?
no curiosity ? and you didn't try it ?
of course that would
but take care of what you write
it is not :
document.getElementById(..]
but
document.getElementById(..)
--
Stephane Moriaux et son [moins] vieux Mac
Geoff Cox a écrit : with an index mismatch in that the element IDs started with question1 (ie 1) but the related array for the text started with 0 and I was using the same num variable for both....
it is a very curent mistake
all as growing to much the loop
--
Stephane Moriaux et son [moins] vieux Mac
On Wed, 12 Oct 2005 00:31:27 +0200, ASM
<st*********************@wanadoo.fr.invalid> wrote: Geoff Cox a écrit : with an index mismatch in that the element IDs started with question1 (ie 1) but the related array for the text started with 0 and I was using the same num variable for both....
it is a very curent mistake all as growing to much the loop
Stephane,
How many times have I told myself to look for the simplest explanation
first !!!
Cheers
Geoff This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: MNF |
last post by:
Hi everyone,
I am using document.getElementById function in JavaScript to find a
control within an html body, but instead I get back META item, because
incidently the name of one meta tags is the...
|
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...
|
by: ctman770 |
last post by:
Hi Everyone,
Is it faster to save the precise location of an html dom node into a
variable in js, or to use getElementById everytime you need to access
the node?
I want to make my application...
|
by: jason.hau |
last post by:
Ok, interesting problem here, I have a webcontrol that holds a textbox
and a requiredfieldvalidator from System.Web.UI.Webcontrols in .NET 2.0
(this is javascript related, bear with me).
The...
|
by: mhito |
last post by:
hi guys,
My first post yes. Thanks for all the nice posts and threads in this forum - great stuff.
Now, here's my question:
First off, the url : http://catfish.businesscatalyst.com/bcimg.htm...
|
by: Bjorndal |
last post by:
I'm new to javascript, so I figure som of you guys in here can answer my question pretty easily:
I have this code which works:
<script type="text/javascript">
</script>
</head>
<body>
|
by: Nick |
last post by:
I've seen a few frameworks use the following:
function $(id) { return document.getElementById(id); }
Then to use:
$('something').innerHTML = 'blah';
I'm just trying to roll this out to my...
|
by: cyqotiq |
last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet.
Second, let me state that this is not the typical "getElementById not working Firefox"...
|
by: GarryJones |
last post by:
The following works in MSIE but not firefox.
I suspect it has something to do with the fact that the element I am
trying to access is not the "tid" which is the name of the DIV that is
passed to...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |