Problem with array only accepting a few rows or elements

J

Jari Hujanen

Hi,

I'm a novice at JavaScript so my problems can be simple for the more
experienced scripters but problems really drive me nuts sometimes. Maybe
someone here sees immediately what is wrong in the next script that I made.
Please help me. The problem is that the code can work with two or a few
rows/elements of the array but when there are more rows in the array,
nothing works anymore. The amount of rows accepted by the script varies.
First, the script only accepted two rows. Then, it suddenly accepted six
rows but I need more rows.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>arrayBusiness</title>
</head>
<body>
<script type="text/javascript" language="javascript">
<!--
var arrayBusiness = new Array();
arrayBusiness[0] = '<h4>Business</h4>';
arrayBusiness[1] = '<ul><li><a
href=\"http://www.nordea.fi/\">Nordea</a></li>';
arrayBusiness[2] = '<li><a
href=\"http://www.aarre.fi/aarre/aloitus.jsp\">Aarre.fi</a></li>';
arrayBusiness[3] = '<li><a
href=\"http://www.kuluttajavirasto.fi/\">Kuluttajavirasto</a></li>';
arrayBusiness[4] = '<li><a
href=\"https://www.palkka.fi/\">Palkka.fi</a></li>';
arrayBusiness[5] = '<li><a
href=\"http://www.prh.fi/fi/kaupparekisteri.html\">PRH:n
Kaupparekisteri</a></li>';
arrayBusiness[6] = '<li><a
href=\"http://www.suomi.fi/suomifi/suomi/asiointi_ja_lomakkeet/\">Suomi.fi
– Asiointi ja lomakkeet</a></li></ul>';
for (i=0;i<arrayBusiness.length;i++) {
document.write(arrayBusiness);
}
//-->
</script>
</body>
</html>
 
R

RobG

Hi,

I'm a novice at JavaScript so my problems can be simple for the more
experienced scripters but problems really drive me nuts sometimes. Maybe
someone here sees immediately what is wrong in the next script that I made.
Please help me. The problem is that the code can work with two or a few
rows/elements of the array but when there are more rows in the array,
nothing works anymore. The amount of rows accepted by the script varies.
First, the script only accepted two rows. Then, it suddenly accepted six
rows but I need more rows.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>arrayBusiness</title>
</head>
<body>
<script type="text/javascript" language="javascript">

Drop the language attribute, it has been deprecated for a long time.
Keep type.

Don't bother with HTML comment delimiters, they just aren't necessary.
var arrayBusiness = new Array();
arrayBusiness[0] = '<h4>Business</h4>';
arrayBusiness[1] = '<ul><li><a
href=\"http://www.nordea.fi/\">Nordea</a></li>'; [...]
arrayBusiness[6] = '<li><a
href=\"http://www.suomi.fi/suomifi/suomi/asiointi_ja_lomakkeet/\">Suomi..fi
– Asiointi ja lomakkeet</a></li></ul>';
for (i=0;i<arrayBusiness.length;i++) {
document.write(arrayBusiness);}


At at guess, between one of the loops for document.write, the load
even fires so the next write cleans out the document, including the
script. Instead of looping, concatenate the string and call
document.write once only, e.g. replace the for loop with:

document.write(arrayBusiness.join(''));

Or just write the string instead of loading it into an array:

document.write(
'<h4>Business</h4>' +
'<ul><li><a ... ' +
...
'...</li></ul>'
);
 
J

Jari Hujanen

Thank you for the advice. I tried without success:
- the document.close() method in the end
- document.write(arrayBusiness.join(''));

In addition to that, I also tried this code (writing the whole string in
document.write as you suggested):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Comp</title>
</head>
<body>
<script type="text/javascript">
document.write('<h4>Business</h4><ul><li><a
href=\"http://www.nordea.fi/\">Nordea</a></li><li><a
href=\"http://www.aarre.fi/aarre/aloitus.jsp\">Aarre.fi</a></li><li><a
href=\"http://www.kuluttajavirasto.fi/\">Kuluttajavirasto</a></li><li><a
href=\"https://www.palkka.fi/\">Palkka.fi</a></li><li><a
href=\"http://www.prh.fi/fi/kaupparekisteri.html\">PRHn
Kaupparekisteri</a></li><li><a
href=\"http://www.suomi.fi/suomifi/suomi/asiointi_ja_lomakkeet/\">Suomi.fi
– Asiointi ja lomakkeet</a></li><li><a
href=\"http://www.syt.fi/\">Suomen Yrittäjäin Työttömyyskassa
(SYT)</a></li><li><a href=\"http://www.vakes.fi/\">Vakuutuskeskus
(Vakes)</a></li>
<li><a
href=\"http://www.vero.fi/default.asp?article=2216&language=FIN\">Vakuutusmaksuvero-ohje</a></li><li><a
href=\"http://www.vm.fi/vm/fi/10_verotus/index.jsp\">Valtiovarainministeriö
– Verotus</a></li></ul>');
document.close();
</script>
</body>
</html>

The previous code didn't work either. I tried that with and without the
document.close() method.

But I got to know about the debugger in IE7 so I used it. The debugger
always complained about an unterminated string constant. I don't understand.
I think I have used single and double quotation marks in matching pairs and
double quotation marks with the escape character in the front of them and I
wrote all the quotation marks anew in Notepad to make sure they don't come
from Word or another unsuitable word processor but nothing helps. I will try
to find info about "unterminated string constant" by Google.


Hi,

I'm a novice at JavaScript so my problems can be simple for the more
experienced scripters but problems really drive me nuts sometimes. Maybe
someone here sees immediately what is wrong in the next script that I
made.
Please help me. The problem is that the code can work with two or a few
rows/elements of the array but when there are more rows in the array,
nothing works anymore. The amount of rows accepted by the script varies.
First, the script only accepted two rows. Then, it suddenly accepted six
rows but I need more rows.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>arrayBusiness</title>
</head>
<body>
<script type="text/javascript" language="javascript">

Drop the language attribute, it has been deprecated for a long time.
Keep type.

Don't bother with HTML comment delimiters, they just aren't necessary.
var arrayBusiness = new Array();
arrayBusiness[0] = '<h4>Business</h4>';
arrayBusiness[1] = '<ul><li><a
href=\"http://www.nordea.fi/\">Nordea</a></li>'; [...]
arrayBusiness[6] = '<li><a
href=\"http://www.suomi.fi/suomifi/suomi/asiointi_ja_lomakkeet/\">Suomi.fi
– Asiointi ja lomakkeet</a></li></ul>';
for (i=0;i<arrayBusiness.length;i++) {
document.write(arrayBusiness);}


At at guess, between one of the loops for document.write, the load
even fires so the next write cleans out the document, including the
script. Instead of looping, concatenate the string and call
document.write once only, e.g. replace the for loop with:

document.write(arrayBusiness.join(''));

Or just write the string instead of loading it into an array:

document.write(
'<h4>Business</h4>' +
'<ul><li><a ... ' +
...
'...</li></ul>'
);
 
J

Jari Hujanen

I got the problem solved. All the different versions of the code work well
now. There was invisible crap at the beginning and mainly at the end of
statements. I copied the end of a statement that worked fine, then I painted
the end of a statement that didn't work and the gap along with the carriage
return between the bad statement and the beginning of the next statement,
finally I pasted the working piece of code with the working and invisible
marks in the gap. Another way to deal with the problem would have been
writing the bad end anew and deleting the gap with the invisible crap and
maybe writing the beginning of the next statement anew in which case the bad
invisible crap gets destroyed from the gap where the carriage return takes
place.

That wasn't very easy to explain but I hope you understand that.


Hi,

I'm a novice at JavaScript so my problems can be simple for the more
experienced scripters but problems really drive me nuts sometimes. Maybe
someone here sees immediately what is wrong in the next script that I
made.
Please help me. The problem is that the code can work with two or a few
rows/elements of the array but when there are more rows in the array,
nothing works anymore. The amount of rows accepted by the script varies.
First, the script only accepted two rows. Then, it suddenly accepted six
rows but I need more rows.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>arrayBusiness</title>
</head>
<body>
<script type="text/javascript" language="javascript">

Drop the language attribute, it has been deprecated for a long time.
Keep type.

Don't bother with HTML comment delimiters, they just aren't necessary.
var arrayBusiness = new Array();
arrayBusiness[0] = '<h4>Business</h4>';
arrayBusiness[1] = '<ul><li><a
href=\"http://www.nordea.fi/\">Nordea</a></li>'; [...]
arrayBusiness[6] = '<li><a
href=\"http://www.suomi.fi/suomifi/suomi/asiointi_ja_lomakkeet/\">Suomi.fi
– Asiointi ja lomakkeet</a></li></ul>';
for (i=0;i<arrayBusiness.length;i++) {
document.write(arrayBusiness);}


At at guess, between one of the loops for document.write, the load
even fires so the next write cleans out the document, including the
script. Instead of looping, concatenate the string and call
document.write once only, e.g. replace the for loop with:

document.write(arrayBusiness.join(''));

Or just write the string instead of loading it into an array:

document.write(
'<h4>Business</h4>' +
'<ul><li><a ... ' +
...
'...</li></ul>'
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top