Páginas

viernes, 9 de enero de 2015

Jade (HTML pre): select tag with options generated automatically with javascript

Today a want to show you a tip about how to make a select with many options without write it one by one and converts it in a long task. This is possible with javascript!

I will show you in Jade (HTML preprocessor and of course, it is possible in HTML as well)
select
option(value='0', selected="1", disabled="1") Option_by_default
script(type='text/javascript').
var number_top = 100;
for(var i = 0; i < number_top; i++) {
document.write('<option value="'+ i +'">'+ i +'</option>');
}
view raw gistfile1.jade hosted with ❤ by GitHub
select
option(value='0', selected="1", disabled="1") Option_by_default
option(value='1') Option 1
option(value='2') Option 2
option(value='3') Option 3
option(value='4') Option 4
option(value='5') Option 5
// and so on...
view raw gistfile2.jade hosted with ❤ by GitHub

No hay comentarios:

Publicar un comentario