0

(sorry my english)

Hey , well i have a select picker:

                    +                       
                    '<select class="selectpicker" id="select_seleccionar_proyecto_id">'
                    +
                    '<option value="0">Seleccione..</option>'
                    +                           
                    '<option value="1">Tarea número 1</option>'
                    +                           
                    '<option value="2">Tarea número 2</option>'
                    +                       
                    '<option value="3">Tarea número 3</option>'
                    +
                    '<option value="4">Tarea número 4</option>'
                    +                           
                    '<option value="5">Tarea número 5</option>'
                    +                       
                    '<option value="6">Tarea número 6</option>' 
                    +                   
                    '</select>'         

this select box is in a modal, and when i close this modal, the select box is like the last time , example: i select "tarea numero 4", i close the modal and open the modal and "tarea numero 4" is selected. Well, i have a method that i call after hide the modal and when i open i need "seleccionar..", but nothing work..

¿what is the best option in jquery? thanks

HideModal: function(){
    var self = this;
    $('#modal_seleccionar_tarea_id').modal('hide');
    self.LimpiarModalTarea();
    },

LimpiarModalTarea: function(){
var self = this;

 $('#select_seleccionar_proyecto_id').val("0");},

PD : this work in other modal, but with textarea.

3 Answers3

2

If you are using bootstrap-select

$("selectorOfSelect").val('0').selectpicker('refresh');
0

i think you are looking for this $("#select_seleccionar_proyecto_id").prop('selectedIndex',0);

stackoverflow Set the selected index of a Dropdown using jQuery

Community
  • 1
  • 1
Theo
  • 1,932
  • 4
  • 17
  • 40
  • selected index not suppose to be access by jQuery object. You need to add `$("#select_seleccionar_proyecto_id")[0].selectedIndex = 0;` to access `selectedIndex` properties. – Norlihazmey Ghazali Apr 21 '15 at 03:35
0

Try change your jquery code

from

$('#select_seleccionar_proyecto_id').val("0");

into

$("#select_seleccionar_proyecto_id")[0].selectedIndex = 0;
               //<<--  or
$("#select_seleccionar_proyecto_id").get(0).selectedIndex = 0;

Normally, by using $('#select_seleccionar_proyecto_id').val("0"); also work, is that LimpiarModalTarea function work when called in hidemodal function?? If did't ensure those function work by putting an alert to ensure that.

Norlihazmey Ghazali
  • 9,000
  • 1
  • 23
  • 40