[Javascript] Javascript arrays

David Lovering dlovering at gazos.com
Thu May 6 07:55:28 CDT 2004


First off, I'd check to see if an element in the object list even has an
attribute 'backgroundColor' before doing a comparison of its value to any
set quantity.

Secondly, unless I'm much mistaken 'browseform' is not a W3C accepted
operator, so in all likelihood the lines that reference it will go spinning
down the drain.  [Of course, if you explicitly have a definition for it
previous to its use of the style

    var browseform = ....

then everything might still be ok].  Lastly, it looks as though you intend
to scan the entire contents of your list (delimeter-separated concatenated
string?) for one or more values.  You should probably declare a working
array thusly

    var myArray = new Array();

And then use "split" or some other construct to parse the content of the
hidden field to fill the array.  Of course, I may be reading this whole
thing wrong, but without the HTML constructs to which your functions point
I'm not sure I'm getting the point of the whole exercise.

Also, you may be doing this the hard way.  If you use the 'onChange' event
handler method, you can tell immediately when a variable (even a hidden one)
has changed state, and can then write code to evaluate the context of the
change only when it is strictly applicable.  When dealing with arrays, it is
sometimes helpful to keep a 'prior copy' of the array and do a diff of it
against the 'new' value (assuming only one entry changes), thereby saving
you the hassle of scanning each entry for inclusion/exclusion changes.  Then
when you actually change the list, roll the now-different list back into the
'prior' one in order to act as a reference for the next diff.

I'd guess my final suggestion is to "show us the code" making up the objects
you wish to manipulate, and then we'll be working from a stronger position.

-- Dave Lovering
----- Original Message ----- 
From: "Terry Riegel" <riegel at clearimageonline.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Thursday, May 06, 2004 4:30 AM
Subject: [Javascript] Javascript arrays


> Hello,
>
> I am new to javascript and would like to convert my code from a brute
> force method to a simpler method. I hope someone can help me out.
>
> First let me say I am very inexperienced in Javascript, not
> programming. So consequently I can understand concepts pretty well, but
> struggle with the simple syntax issues.
>
> Here is part of the function:
>
> function changedest(dest,type)
> {
>    var td = document.getElementById(dest);
>    if (td.style.backgroundColor == '#BFD7FF')
>     {
>       td.style.backgroundColor = '#FFFFFF';
>       document.browseform["fm_list"].value =
> document.browseform["fm_list"].value.replace("|"+dest,"");
>     }
>    else
>     {
>       td.style.backgroundColor = '#BFD7FF';
>       document.browseform["fm_list"].value =
> document.browseform["fm_list"].value+"|"+dest;
>     }
> }
>
>
> The hidden field will contain the list of selected items like and gets
> updated when a user clicks on a link if its in the list it gets
> removed, if not it gets added. The problem is I am using the background
> color to determine the status of the list, and there are situatiuons
> when the background color and the list are out of sync. I would like to
> create a way for the background color to be set from the list, but I
> have no idea how to proceed. I have created a deselect() function, but
> it is very crude. Here it is.
>
> function deselect()
> {
> var td = document.getElementById('.TEMP');
> td.style.backgroundColor = '#ffffff';
> var td = document.getElementById('app');
> td.style.backgroundColor = '#ffffff';
> var td = document.getElementById('apps');
> td.style.backgroundColor = '#ffffff';
> etc...
> }
>
>
> Thanks for any help with this.
>
> Terry Riegel
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>





More information about the Javascript mailing list