Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] accessing javascript array value inside the select tag


  • From: javascript@xxxxxxxxxx (Bill Marriott)
  • Subject: [Javascript] accessing javascript array value inside the select tag
  • Date: Mon, 30 Dec 2002 21:29:39 +1100

Hi

Something like this may be what you need to set the options dynamically ( if
that is what you are trying to do).
You will need to declare all the variables.

comboObj.options.length = 0;
 var i;
  for (i = 0; i < myarray.length; i++)
    {
           var pOption=document.createElement("OPTION");
           pOption.value=myarray[i][0];
           pOption.text=myarray[i][1];
           comboObj.options.add(pOption);
    }

Bill



----- Original Message -----
From: "Andrew Gibson" <andyg@xxxxxxxxxx>
To: <javascript@xxxxxxxxxx>
Sent: Monday, December 30, 2002 2:26 PM
Subject: Re: [Javascript] accessing javascript array value inside the select
tag


> I think probably you'd put those arrays in with a server side script
>
> Something like:
>
> <option value="<%=collegeId(i)%>">"<%=collegeName(i)%>"</option>
>
> If you needed to access the collegeName(i) you could always go
>
>
> <option value="<%=collegeId(i)&"|"&collegeName(i)%>">
>
> Then the value is, say,   1|My college
>
> and you can parse out the id etc with Javascript.
>
> > My question was confusing. It's like this :
> > I have a script like this :
> >
> > <SCRIPT LANGUAGE="JavaScript">
> > <!--
> > var collegeName = new Array('NMAMIT','NIT','NIIT');
> > var collegeId = new Array('001','002','003','004');
> > //-->
> > </SCRIPT>
> >
> > now i have a select tag in which i want to have
> > <option value=collegeId[i]>collegeName[i]</option>
> > where i is the index of the array
>
>
>
> _______________________________________________
> Javascript mailing list
> Javascript@xxxxxxxxxx
> https://lists.LaTech.edu/mailman/listinfo/javascript
>