El cuadro jQuery Select no se mostraba si no se seleccionaba con un clic

tengo dos select boxes. One with list of Cities and the second one with Districts of Cities. When I chose (by click) the City from the first select box in the second box I see districts from selected City. That work perfectly, but when the City is selected automaticly by another script, the list of districts doesn't show - i have to manualy select the city from the list and then the list of districts appear.

Aquí está mi guión:

$.viewMap_get = {
    '0' : $([]),
    'Katowice' : $('#c1a, #c1b, #c6, #c7'),
    'Kraków' : $('#c2a, #c2b, #c6, #c7'),
    'Warszawa' : $('#c3a, #c3b, #c6, #c7'),
    'Wrocław' : $('#c4a, #c4b, #c6, #c7'),
    'Gdańsk' : $('#c5a, #c5b, #c6, #c7'),

$.each($.viewMap_get, function() { this.hide(); });

$('#get_car').on('change', function() {
// hide all
$.each($.viewMap_get, function() { this.hide(); });
// show current

  var id = $.viewMap_get[$(this).val()].attr("id");   
  $('#'+id).attr('selected', 'selected');

¿Alguien podría ayudar?

preguntado el 31 de julio de 12 a las 12:07

Do you mean a city is being set by a server-side script, or by another JavaScript script? -

by JavaScript - compute function -

Well then I can't imagine why it doesn't work, since that will still trigger the change event. Does that not fire? Put an alert in to find out. Can you set up a Fiddle? -

i will try to put it in to Fiddle -

1 Respuestas

Try this (See DEMO [in the end of js])

$('#get_car option:eq(2)').attr('selected', 'selected');

Respondido 31 Jul 12, 13:07

the scritp should display the same list under the city2 with krakow districts. how it works. If the total day is less than 3 the value of the field City1 is transferred automatically into the City2. Under each of the cities should be displayed the list of Districts. however, if the value is copied from the City1 to city2 the list of Districts is not displayed - Adrian

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.