[thelist] How can I pass a HTML "array" over to Javascript

ben morrison morrison.ben at gmail.com
Thu Aug 24 08:49:48 CDT 2006


On 8/24/06, Stefan Schwarzer <st.schwarzer at geois.de> wrote:
> Hi there,
>
> I have a kind of HTML array ("layer[]"), which appears a couple of
> times on my form. It is used so that a user can select multiple
> layers to be displayed on a map. So, this would be "cities",
> "national boundaries", "lakes", "rivers", etc.
>
> It works fine. No problem with that.
>
> Now, I would like, before passing the elements over to PHP, to do a
> quick check with Javascript which layers have been selected, in order
> to eliminate eventually one or to add another.
>
> My function to do this looks like this:
>
>                  function change_level()
>                  {
>                      lyr = new Array();
>                      lyr = document.mapserv.layer;
>                      for (i=0; i<lyr.length; i++)
>                      {
>                         if (lyr[i] = "cities")
>                                 ... eliminate that layer
>                      }
>                  }
>
> So, here I have a (actually two) problems. One is that I have no clue
> how the HTML element "layer" can be passed over to a Javascript-
> variable. And second I don't know how I can eliminate one element of
> that array.
>
> There probably would be some possibility to get the checking done in
> PHP too, but the whole process behind the site is somewhat complex.
> So it would come in very handy, if this would be achievable through
> Javascript.

Ok, I think I understand what you have, maybe a URL would help though.

What would make sense to me would be a series of checkboxes inside the form.

[ ] Show boundaries
[ ] Show rivers
...

This would make it very simple to get the required data when the form
is submitted, there would be no need for javascript - although this
could enhance the form. You will also need to check the form contents
anyway with PHP if the user has javascript disabled. This solution
would be easy to implement/update and is accessible.

ben

-- 
Ben Morrison



More information about the thelist mailing list