User:KhangND/common.js

/* Selector */ /* Description: Display content using Select menu. @uthor: KhangND */ var containers = $('.sel-container'); var fields = $('.fields');

for (indx = 0; indx < containers.length; indx++) { var cur = indx + 1; var selector = '#select' + cur; var max = fields[indx].children.length / 2; //fields count $(fields[indx]).attr('id', 'select' + cur);

//Select $select = $(' ', {       id: 'selector' + cur,        onchange: 'change(' + cur + ')',        appendTo: $(containers[indx])    });

//Options for (i = 1; i <= max; i++) { $(' ', {           value: i,            text: $(selector + ' #option' + i).text,            appendTo: $select        }); // hide field names on desktop $(selector + ' #name' + i).css('display', 'none'); // show field 1 upon loaded if (i !== 1) $(selector + ' #field' + i).css('display', 'none'); } }

//Onchange handler function change(indx) { var selector = '#select' + indx; var option = $('#selector' + indx).val; for (i = 1; i <= max; i++) { if (i != option) $(selector + ' #field' + i).css('display', 'none'); else $(selector + ' #field' + i).css('display', ''); } }