Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/10/2013, 16:28
Avatar de AnGuisi
AnGuisi
 
Fecha de Ingreso: julio-2013
Ubicación: San Felipe - Yaracuy
Mensajes: 122
Antigüedad: 10 años, 10 meses
Puntos: 2
Cargar Select en funcion jQuery

Quiero recargar un select con contenido de mi base de datos mysql, pero dentro de una función jQuery.

Ya he realizado esto directamente en html pero sucede que cree esta funcion con jQuery:

Código Javascript:
Ver original
  1. $(document).ready(function() {
  2.  
  3.                 var MaxInputs       = 8; //maximum input boxes allowed
  4.                 var contenedor      = $("#contenedor"); //Input boxes wrapper ID
  5.                 var AddButton       = $("#agregarCampomodelo"); //Add button ID
  6.  
  7.                 //var x = contenedor.length; //initlal text box count
  8.                 var x = $("#contenedor div").length + 1;
  9.                 var FieldCount = x-1; //to keep track of text box added
  10.  
  11.                 $(AddButton).click(function (e)  //on add input button click
  12.                 {
  13.                         if(x <= MaxInputs) //max input box allowed
  14.                         {
  15.                             FieldCount++; //text box added increment
  16.                             //add input box
  17.                             $(contenedor).append('<div class="added"><fieldset><input type="text" name="marca[]" id="marca_'+ FieldCount +'" /><select type="text" id="marca"  name="marca[]" value="" ><option value="">Seleccione Marca</option>#COMBO#</select><a href="#" class="eliminar">&times;</a></fieldset></div>');
  18.                             x++; //text box increment
  19.                         }
  20.                 return false;
  21.                 });
  22.  
  23.                 $("body").on("click",".eliminar", function(e){ //user click on remove text
  24.                         if( x > 1 ) {
  25.                                 $(this).parent('fieldset').remove(); //remove text box
  26.                                 x--; //decrement textbox
  27.                         }
  28.                 return false;
  29.                 });
  30.  
  31.             });

Esto lo que hace es agregar y quitar campos, pero necesito agregar un select ya cargado con datos. Como podria lograr esto? Ya se hacerlo con PHP, inclusive esta parte del codigo

Código HTML:
Ver original
  1. <select type="text" id="marca"  name="marca[]" value="" ><option value="">Seleccione Marca</option>#COMBO#</select>
la estoy utilizando en otro archivo y sustituyo la palabra "#COMBO#" por el select cargado que extraigo desde un archivo PHP. Como puedo lograr esto mismo desde JavaScript?