summary summary - 1 year ago 88
jQuery Question

how to convert tapestry arraylist into array in jquery

I am working on an application that uses tapestry , jquery , ajax .

I need to get a drop down to act as autocomplete drop down.
So i think of taking drop down option arraylist into an array and write autocomplete method to it .
below is existing code

<td ><span jwcid="countryList"
onChange="javascript:onChangeCountry(this);" />

Above tag converts into drop down box at run time with id = countryList.

I want to get text values of countryList into an array , how can i do it ?
I tried below method , but it only gave me first index 's text .

var carray= [];
$('#countryList :selected').each(function(i, selected){
carray[i] = $(selected).text();

$( "#xyz" ).autocomplete({
source: carray

How can i get all text values in carray ?

What am i doing wrong ?

Please help .

Thanks Much.

Answer Source

You can read the option like this. You can try with this code instead:

var options = [];
$(document).ready(function() {
  $('#myselect option').each(function(i, selected) {
    options[i] = ($(selected).text());

<script src=""></script>
<select id="myselect">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download