limit on number or size of javascript variables

A

Andy Fish

Hi,

I am in the process of designing a UI which has to be fairly sophisticated.
There will be a number of list boxes and other controls, with pop-up windows
to edit certain properties. It's the kind of thing I would normally have
done in VB but I want it to be browser-based. I've only used javascript for
trivial things before so this would be my first serious javascript
development. I would like it to run on all reasonably recent browsers.

The form starts with all the initial values being received from the server
(presumably just by pre-initialised data structures). The user tinkers with
it and when he is happy he presses 'submit' and the whole lot is submitted
to the server (presumably as a form post). This would be a few kb of data,
possibly 100 individual values but obviously in various data structures. I
guess there would be a few hundred lines of javascript code to manipulate
it.

My question is, is there likely to be a problem with manipulating and
sending this amount of data in Javascript. Sorry if this is a dumb question,
but like I said, I only used javascript for tiny programs before, so I'm a
bit unsure about its capabilities.

Boastful replies of the form "I have an X thousand line javascript program
that runs in all browsers and manipulates Y megabytes of data" would be most
welcome :)

Andy
 
G

Grant Wagner

Steven said:
Not a dumb question, but one based on a lack of background.
Javascript does not submit the data; the form does that.
The values are not javascript variables. In fact, your form does
not seem to need any Javascript at all, unless there is something you
haven't mentioned. Forms using the 'get' method are restricted to
(I think) 256 bytes, but the 'post' method can easily handle your few kb of
data.

While I wouldn't suggest using a URI longer than about 256 characters, I did do
some testing and this is what I found:

There is a restriction on the length of a URI (including any parameters). In
IE6SP1, the longest URI I could construct that would not be truncated was 2083
bytes:

<body onload="alert(window.location.href.length);">
<script type="text/javascript">
String.prototype.repeat = function(times) {
return (new Array(times + 1)).join(this);
}

var s = "X";
s = s.repeat(2003);

document.write('<a href="hs~new.htm?p=' + s + 'Y">Test</a>');
</script>

Note that in my case, the original URL was 77 bytes, adding '?p=', the repeating
X and the Y brought it to 2083. Anything longer then that and IE simply dropped
everything after the '?' when navigating to the new page. Netscape 4.78, Mozilla
1.5a and Opera 7.11 had no problems with longer URL, although I did not actually
test to see if client-side JavaScript was capable of reading the passed values.

I also didn't test the maximum length of URI that every browser can recognize,
but it seems that the "big three" modern browsers can handle URI well in excess
of 256 characters.

Also be aware that someone else performed similar tests and got slightly
different results (I believe they were able to construct a URI of only 2076
bytes in IE).
 
A

Andy Fish

OK, maybe I should be clearer about my requirements.

The user will be maintaining a small set (2-10) of records. Because of the
interrelationships between the records I don't want to commit changes each
time the user navigates, so I want to store the data in an array of
structures (sorry if this is not the correct javascript terminonogy). As the
user navigates between the records the javascript will populate the fields
on the screen and copy changes back into the array. When the user is happy,
he presses the 'submit' button and all the changes are submitted,

so the fields he sees on the screen aren't directly what gets posted to the
server. I thought I might build all the results into an XML string and post
it in a hidden text field or something, but I haven't really gone that far
into the design yet.

This is the way I would have done it in VB, but I'm not sure if this makes
sense for javascript

Thanks

Andy
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top