473,472 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

js code

I would like a script to display a list of web links that will be ever
increasing. I don't want to have to do a new document.write command for
each new variable as it comes up. The larger var numbers will be at the
top, so I can add to them as I need to.

var 2l = "hp.com"
var 2t = "HP"

var 1l = " www .ibm.com"
var 1t = "IBM"

..........(and so on)

document.write('<a href=http://');
document.write(1l);
document.write('>');
document.write(1t);
document.write('</a><br>');

repeat some how
I am doing this as I have a palm that can sync js files, so I do updates to
web files when I am away from a computer. I have done this for over a year
now and it works well. I have several cases similar to this that I have to
have to use if/then statements to not display values if they are not there.

I hope that I made sense.


Jul 20 '05 #1
3 1977
> I would like a script to display a list of web links that will be ever
increasing. I don't want to have to do a new document.write command for
each new variable as it comes up. The larger var numbers will be at the
top, so I can add to them as I need to.


First recommendation: don't use individual variables, but an array. That is much more convenient and suitable
for your task.

Second recommendation: you can combine individual document.write() statements by using plus signs (+).

May I, thirdly, recommend this code to you:

var links=new Array();
links[0]=new Array("hp.com","Hewlett-Packard");
links[1]=new Array("ibm.com","IBM");
links[2]=new Array("slashdot.org","News for nerds, stuff that matters.");
// and so on ...

for (var i=links.length-1;i>=0;i--)
{
document.write('<a href="http://' + links[i][0] + '">' + links[i][1] + '</a><br />');
}

As requested, this will sort the array upside down (i.e. descending by number).
Basically, all you've got to do is adding lines like
links[bla]=new Array("bla","bla");
to the upper part of the script.

(code tested on Win32/Opera 7.20)

Fourth recommendation: Try to avoid subjects like "js code" on comp.lang.javascript ... that's like showing up
at Burger King and loudly proclaiming nothing more than that you'd like to eat something :)
Try to give a clear subject that is specific to your question, or not many people will bother reading it.

Best Regards ;)
Hendrik Krauss

Jul 20 '05 #2

"Hendrik Krauss" <us****@removethis.hendrik-krauss.andthat.de> wrote in
message news:3f***********************@news.freenet.de...
First recommendation: don't use individual variables, but an array. That is much more convenient and suitable for your task.

Second recommendation: you can combine individual document.write() statements by using plus signs (+).
May I, thirdly, recommend this code to you:

var links=new Array();
links[0]=new Array("hp.com","Hewlett-Packard");
links[1]=new Array("ibm.com","IBM");
links[2]=new Array("slashdot.org","News for nerds, stuff that matters.");
// and so on ...

for (var i=links.length-1;i>=0;i--)
{
document.write('<a href="http://' + links[i][0] + '">' + links[i][1] + '</a><br />'); }

Fourth recommendation: Try to avoid subjects like "js code" on comp.lang.javascript ... that's like showing up at Burger King and loudly proclaiming nothing more than that you'd like to eat something :) Try to give a clear subject that is specific to your question, or not many people will bother reading it.
Best Regards ;)
Hendrik Krauss

Thank you so much for this, it will help out greatly with my coding. I
wanted to have something in the subject line that talked about this, but did
not have ANY idea what to call it, so thank you for taking the time to help.
For future reference what should I have put in the subject line on this one?

Also, is there a limit on how many characters I can put in an array? One of
the web sites that I manage is a car dealership that has a short description
about the vehicle, make model year of the vehicle, price, and monthly
payments.
Jul 20 '05 #3
> For future reference what should I have put in the subject line on this one?

How about "Handling great number of variables efficiently?" ... uhm ... I'd say something like
"Scaling this script to deal with many variables" ... maybe "Big amout of data makes coding painful" ... "Bad
efficiency when introducing many variables" ... "Script won't scale well"

Well, something like that. I'm not an authority on subjects, either :)
Take the above proposals, insert own ideas randomly, and throw together your own subject from that. :)
Also, is there a limit on how many characters I can put in an array?


Don't know exactly ... I just conducted a quick test and was able to create two arrays, containing 100000 and
half a million string objects, though that took a while on my old machine:

Creating array w/100,000 elements*
Opera 0.8 sec, IE 6.5 sec

Creating array w/500,000 elements*
Opera 3.3 sec, IE 2 min 40 sec

Didn't check two- or more-dimensional arrays though. (Maybe you've noted that the code I posted contained a
2-d array, which is basically an array containing arrays. Imagine an array as a "list" of things (has one
column), and a 2-d array as a "table" of things (has >1 column)--like the "links" array containing entries
that were in themselves arrays containing name and url.)

So I guess in terms of processing time, element counts with five figures will generally be ok on pretty much
every system; with element counts greater than that you are on the verge of becoming annoying for some users.
Also bear in mind that Javascript is completely client-side, so every chunk of data you may want to access via
script has to be transferred to the client (i.e.: everything must be in your page's source code, which has to
be downloaded prior to execution). So if you shovel, say, the humongous multi-megabyte database (contained in
a Javascript) through the visitor's 56 K connection, you'd better have one heck of a good reason for that :)
You can certainly put a lot of data into the arrays on your page, but keep an eye on the file size.

Good coding!

Best regards
Hendrik Krauss
* all figures: Opera 7.20, Internet Explorer 6.0, Athlon 1.2 GHz, 512 MB RAM, WinXP

Jul 20 '05 #4

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

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
4
by: KenFehling | last post by:
Hello. I am wondering if there exists a piece of software that takes multiple .js files that are nicely indented and commented and create one big tightly packed .js file. I'm hoping the one file...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
7
by: blackrosezy | last post by:
#include char *code; void main() { char buf = "book";
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
1
by: ahammad | last post by:
Hello, I have written a fairly complex parsing tool that is used to parse information from company documents. The program works very well, but in order to insure that all the data is copied...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
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
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
jinu1996
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.