Click to See Complete Forum and Search --> : arrays and populating txt boxes


idiotbear
07-18-2003, 03:39 AM
hey there

I have an ASP VBScript recordset which supplies the value and the label of a select box (ClientID and ClientName respectively).

I've created a JS array called "aTrusts" from this recordset so that I can use the data to populate text fields in my form with values, depending on the value of the select box.

So obviously I need to write a JS function, triggered by OnChange in the select box, which finds the relevant "row" and "column" of the array by looking for the ClientID and sets the value of the text field accordingly.

How the flying f*ck to I do this? lol

Is it even possible? Does JS support multi-dimensional arrays?

HELP!

:)

Gollum
07-18-2003, 07:40 AM
You will find Javascript arrays and objects bend over backwards to try and give you what you want.

Are your clientIDs contiguous? Start from zero?

if not, you might consider using an object rather than an array to store the collection of row data. Consider this...


var aTrusts =
{
tom:["brown",24,"123 A Place, somewhere"],
dick:["long", 36, "No Fixed Abode"],
harry:["day", 40, "Unit 6, New Life Flats"]
};


function select_onchange(oSel)
{
// the value from the combo box is the client id (one of "tom", "dick" or "harry")
var aValues = aTrusts[oSel.value];

alert("last name = " + aValues[0]);
alert("age = " + aValues[1]);
alert("address = " + aValues[2]);
}

idiotbear
07-18-2003, 08:18 AM
no, they're not remotely contiguous lol :D

here's a sample of the array:

var aTrusts = new Array(
new Array('Deutsche International Trust Corporation (C.I.) Limited','St Paul's Gate','New Street','St Helier','Jersey','JE4 8ZB','','135 Bishopsgate Limited','R50418'),
new Array('Hampden House','Great Hampden','Buckinghamshire','HP16 9RD','','','','AA Mutual International Insurance Co Ltd Trust','R50595')

There are actually about 400 more new Array rows than that...

idiotbear
07-21-2003, 04:17 AM
OK...

Through a superhuman effort in VBScript I've now forced my VBS recordset into a nice JS array.

Here's a couple of example "rows":

var aTrusts = new Array()
aTrusts[0] = New Array(clientno1, client1address1, client1address2, client1address3, client1address4, client1address5, client1address6; );

aTrusts[1] = New Array(clientno2, client2address1, client2address2, client2address3, client2address4, client2address5, client2address6; );

etc etc


soooooooooooooooooooo....

I want my combo (document.forms[0].trust) to call a function onchange, so that if document.forms[0].trust.value = clientno1, it will set the values of document.forms[0].clientaddress to client1address1 from the array, etc etc

does that make sense?

R

Khalid Ali
07-21-2003, 09:30 AM
you should get Idea from this script below
http://68.145.35.86/skills/javascripts/DropDownShowSelectionInTextField.html

What you'd need to do is pass the selectedIndex value to the function in the onchange event....
then with that index value you'd get the from the array list create an array object that is at that indext in the main array

var tempArr = aTrusts[index];
now you have the array object at the index above,

since client1address1 is the second value in the sub array collection you can access it just as you would for any other array

document.formName.textFieldName.value = tempArr[1];

the above will show the address in the text field