I'm using a library of jquery DDslick to fill the input selects with styles even images, the library uses arrays to fill them for example ..
var data=
[
{ text: "Facebook",//este es el texto que se ve en la cabecera
value: 1,//este es el valor de el select,puedes poner el que quieras
selected: false//opccion si deceas que este seleccionado o no
}
]
this div would be the select emulator
<div id="Dropdown"></div><!--este seria el emulador del select-->
and that would be how it would fill that div to be a select
$('#Dropdown').ddslick({
data:data,//esta es la variable data que llenara el div
width:300,//manipular estilos del select
selectText: "Select your preferred social network",
imagePosition:"right",
onSelected: function(selectedData){//este metodo serai el onchange
//callback function: do something with selectedData;
}
});
this is the Documentation of the library if you are interested
Now, what I want to do is fill an array with dates of a for
, so write dates from 1970 to 2020 one by one in a array would not be very funny of say XD, so I need the array to have the same structure that the library uses so I can accept it hopefully understand me, in this snipper you will see the selects with styles p>
//Dropdown plugin data
var ddData = [{text:"any",value:"any"}];
// Si el objeto es igual puedes hacer algo así.
for(var i=1970; i<2020; i++){
// Tu fecha
var dataFecha=i;
// Creas un nuevo objeto.
var objeto = {
// Le agregas la fecha
fecha: dataFecha,
text: i,
value: i,
selected: false
}
ddData.push(objeto);
}
$('#Dropdown').ddslick({
data:ddData,
width:300,
height:300,
selectText: "vehicle year",
imagePosition:"right",
onSelected: function(data){
var d=data.selectedData.value;
$("#show").html(d)
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/prashantchaudhary/ddslick/master/jquery.ddslick.min.js" ></script>
<div id="Dropdown"></div>
<div id="show"></div>
<div id="fecha"></div><!--need to fill out this one width date-->
What I would like to fill this array with dates something like this but the truth is that I do not know how to do it well so I resorted to you, I hope you can help me thanks!
for(var i=1970; i<2020; i++){
var dataFecha=i;
}