Session variables and arrays

S

sjsean

All thanks in advance for reading my post. I am new to using js and
more accustomed to vbscript.

I had written code which created a shopping cart into an array using
vbscript and then transferred the information into a session
variable. However what I didn't know was that deleting/manipulating
information in an array using vbscript was not that easy.

In doing some reading and research it seemed that js was more flexible
in this area. My questions:

1) if I want to store cart items/details in an array and session
variable do I need to use only js (and can not switch back and forth
from vbscript and js)

2) if I have an array 6x12 and want to delete all the items
associated with say arrayItem[1, 0...12] what is the proper coding to
delete...is it splice?

3) any good articles about js, arrays, and multidimensional arrays
for a beginner?

sean
 
R

RobG

All thanks in advance for reading my post. I am new to using js and
more accustomed to vbscript.

I had written code which created a shopping cart into an array using
vbscript and then transferred the information into a session
variable. However what I didn't know was that deleting/manipulating
information in an array using vbscript was not that easy.

In doing some reading and research it seemed that js was more flexible
in this area. My questions:

1) if I want to store cart items/details in an array and session
variable do I need to use only js (and can not switch back and forth
from vbscript and js)

I'm not sure what you mean by session variable, let's just talk about
javascript Array objects. As far as I know, you can mix javascript
and VBscript in the same page if they are in separate script elements,
you are using IE and you follow appropriate syntax so ID knows what is
VBscript and what is javascript. It is a very bad idea, I don't
recommend it at all - stick with one or the other, preferably
javascript if you want it to run in any browser other than IE.

2) if I have an array 6x12 and want to delete all the items
associated with say arrayItem[1, 0...12] what is the proper coding to
delete...is it splice?

It depends what you mean by delete. If you have an array of 12 items
with index 0 to 11, you can assign any value you like to any element,
so one version of delete might be to simply set an element's value to
'null' or ''.

If you use the Array splice method (which can be used to remove a
range of elements, not just one), the element is removed and your
array now has indexes 0 to 10 and a length of 11. You can also use
shift and pop to remove the first and last elements respectively.

3) any good articles about js, arrays, and multidimensional arrays
for a beginner?

For a brief introduction to javascript arrays (don't use for..in with
arrays, though it's good to know it's there):

<URL: http://www.w3schools.com/js/js_obj_array.asp >

Then search the archives here. The ECMAScript specification isn't too
bad for arrays either, have a read and a bit of a play.

Some extras - initialise arrays using an initializer rather than a
constructor:

var arrayA = [];
var arrayB = ['foo', 'bar', 0, function(){...}];


The length property is automatically set as the largest used index
plus 1.

Sparse arrays are possible:

arrayA[10] = 'ipsum';
arrayA[100] = 'lorem';
alert(arrayA.length); // shows 101
 
S

shimmyshack

All thanks in advance for reading my post. I am new to using js and
more accustomed to vbscript.

I had written code which created a shopping cart into an array using
vbscript and then transferred the information into a session
variable. However what I didn't know was that deleting/manipulating
information in an array using vbscript was not that easy.

In doing some reading and research it seemed that js was more flexible
in this area. My questions:

1) if I want to store cart items/details in an array and session
variable do I need to use only js (and can not switch back and forth
from vbscript and js)

2) if I have an array 6x12 and want to delete all the items
associated with say arrayItem[1, 0...12] what is the proper coding to
delete...is it splice?

3) any good articles about js, arrays, and multidimensional arrays
for a beginner?

sean


Hiya Sean
1)
My advice is store any and all sensitive data on the server, and
manipulate it there. Bear in mind that you will end up doing this
anyway, or someone could manipulate the javascript and if you dont
check it before using it, you could end up out of pocket.
Javascript should not be used as the core of any web app, but to
augment it for those with javascript enabled. This is really waht
sessions are for, the server side storage and manipulation of data so
that a user agent doesnt have to keep track of it all!

I'll leave 2 and 3 to someone else I think, but basically I would say
http://www.w3schools.com/js/js_obj_array.asp
something like that, or this: http://www.w3schools.com/jsref/jsref_obj_array.asp
 
H

Hal Rosser

sjsean said:
All thanks in advance for reading my post. I am new to using js and
more accustomed to vbscript.

I had written code which created a shopping cart into an array using
vbscript and then transferred the information into a session
variable. However what I didn't know was that deleting/manipulating
information in an array using vbscript was not that easy.

In doing some reading and research it seemed that js was more flexible
in this area. My questions:

1) if I want to store cart items/details in an array and session
variable do I need to use only js (and can not switch back and forth
from vbscript and js)

2) if I have an array 6x12 and want to delete all the items
associated with say arrayItem[1, 0...12] what is the proper coding to
delete...is it splice?

3) any good articles about js, arrays, and multidimensional arrays
for a beginner?

sean

You're alluding to ASP programming, which is server-side. I believe the main
focus of this group is Client-Side Javascript.
Although you can use Javascript ( JScript) in lieu of VBScript for your ASP,
there's no need to switch from VBScript soley for handling a rectangular
array. If you're accustomed to the first element having an index of 1, and
accustomed to being able to ReDim your array, you may find the learning
curve switching to JScript a bit steeper than you may have anticipated. You
may ask yourself, for example, why do I want to delete elements of an array
in the first place.
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top