8 examples of 'populate dropdown using jquery json' in JavaScript

Every line of 'populate dropdown using jquery json' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
405function populate_dropdown (query, results) {
406 if(results.length) {
407 dropdown.empty();
408 var dropdown_ul = $("<ul>")
409 .appendTo(dropdown)
410 .mouseover(function (event) {
411 select_dropdown_item(get_element_from_event(event, "li"));
412 })
413 .mousedown(function (event) {
414 add_token(get_element_from_event(event, "li"));
415 return false;
416 })
417 .hide();
418
419 for(var i in results) {
420 if (results.hasOwnProperty(i)) {
421 var this_li = $("<li>"+highlight_term(results[i], query)+"</li>")
422 .appendTo(dropdown_ul);
423
424 if(i%2) {
425 this_li.addClass(settings.classes.dropdownItem);
426 } else {
427 this_li.addClass(settings.classes.dropdownItem2);
428 }
429
430 if(i == 0) {
431 select_dropdown_item(this_li);
432 }
433
434 $.data(this_li.get(0), "tokeninput", results[i]);
435 }
436 }
437
438 dropdown.show();
439 dropdown_ul.slideDown("fast");
440
441 } else {
442 dropdown
443 .html("<p>"+settings.noResultsText+"</p>")
444 .show();
445 }
446}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

704function populate_dropdown (query, results) {
705 if (results && results.length) {
706 dropdown.empty();
707 var dropdown_ul = $("<ul>")
708 .appendTo(dropdown)
709 .mouseover(function (event) {
710 select_dropdown_item($(event.target).closest("li"));
711 })
712 .mousedown(function (event) {
713 add_token($(event.target).closest("li").data("tokeninput"));
714 hidden_input.change();
715 return false;
716 })
717 .hide();
718
719 $.each(results, function(index, value) {
720 var this_li = settings.resultsFormatter(value);
721
722 this_li = find_value_and_highlight_term(this_li ,value[settings.propertyToSearch], query);
723
724 this_li = $(this_li).appendTo(dropdown_ul);
725
726 if (index % 2) {
727 this_li.addClass(settings.classes.dropdownItem);
728 } else {
729 this_li.addClass(settings.classes.dropdownItem2);
730 }
731
732 if (index === 0) {
733 select_dropdown_item(this_li);
734 }
735
736 $.data(this_li.get(0), "tokeninput", value);
737 });
738
739 show_dropdown();
740
741 if (settings.animateDropdown) {
742 dropdown_ul.slideDown("fast");
743 } else {
744 dropdown_ul.show();
745 }
746 } else {
747 if (settings.noResultsText) {
748 dropdown.html("<p>"+settings.noResultsText+"</p>");
749 show_dropdown();
750 }
751 }
752}
20function setDropdownValues($dropdown, values, selectedValue) {
21 $dropdown.empty();
22 var optionsAsString = '';
23 // add an empty string to the beginning for empty selection
24 values.unshift('');
25 $.each(values, function () {
26 optionsAsString += "<option value='" + escapeHtml(this) + "'" + (selectedValue == this ? " selected='selected'" : "") + ">" + escapeHtml(this) + "</option>";
27 });
28 $dropdown.append($(optionsAsString));
29}
47function addToDropdown(template) {
48 $("#templateDropdownSelections").append("<li><a onClick='setTemplate(\"" + template + "\")' href='#'>" + template + "</a></li>");
49}
69function setDropdownValue(event) {
70 var dt = event.target.parentNode.parentNode.previousSibling;
71 dt.value = event.target.getAttribute("value");
72 dt.firstChild.textContent = event.target.textContent;
73
74 dt.parentNode.setAttribute("dropped", "false");
75
76 var evt = document.createEvent("HTMLEvents");
77 evt.initEvent("change", true, true);
78 dt.dispatchEvent(evt);
79}
8function populateDropdown(dropdown, dgo) {
9 for (var i = dgo.min; i <= dgo.max; i++) {
10 var option = document.createElement("option");
11 option.setAttribute("value", i);
12 if (i === dgo.default) option.setAttribute("selected", '');
13 option.innerHTML = i;
14 dropdown.appendChild(option);
15 }
16}
97function openDropdown(event) {
98 if($this.parents(".navbar").find(".navbar-toggle").is(":visible")) {
99 // If we're inside a navbar, don't do anything when the
100 // navbar is collapsed, as it makes the navbar pretty unusable.
101 return;
102 }
103
104 // clear dropdown timeout here so it doesnt close before it should
105 window.clearTimeout(timeout);
106 // restart hover timer
107 window.clearTimeout(timeoutHover);
108
109 // delay for hover event.
110 timeoutHover = window.setTimeout(function () {
111 $allDropdowns.find(':focus').blur();
112
113 if(settings.instantlyCloseOthers === true)
114 $allDropdowns.removeClass('open');
115
116 // clear timer for hover event
117 window.clearTimeout(timeoutHover);
118 $this.attr('aria-expanded', 'true');
119 $parent.addClass('open');
120 $this.trigger(showEvent);
121 }, settings.hoverDelay);
122}
73function buildDropdown(items, trumbowyg) {
74 var dropdown = [];
75
76 $.each(items, function (i, item) {
77 var btn = 'mention-' + i,
78 btnDef = {
79 hasIcon: false,
80 text: trumbowyg.o.plugins.mention.formatDropdownItem(item),
81 fn: function () {
82 trumbowyg.execCmd('insertHTML', trumbowyg.o.plugins.mention.formatResult(item));
83
84 return true;
85 }
86 };
87
88 trumbowyg.addBtnDef(btn, btnDef);
89 dropdown.push(btn);
90 });
91
92 return dropdown;
93}

Related snippets