Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
| Currently I am having a dropdown which contains items when i choose one item from dropdown there is a list box which gets populated with list of items corresponding to the item choosen from dropdown. But I want only those items should come inside list box whose value is real means it should be number.. |
This is my javascript
$(document).ready(function() {
$.ajax({
url: "avb.json",
dataType: "json",
success: function(obj) {
console.log("obj--", obj)
var jsObject = obj;
var usedNames = [];
$('<option>', {
text: 'Select your Option',
value: '',
selected: 'selected',
disabled: 'disabled',
location: 'fixed'
}).appendTo('#dropdown1')
$.each(obj, function(key, value) {
if (usedNames.indexOf(value.name) == -1) {
$("#dropdown1").append("<option value=" + key + ">" + value.name + "</option>");
usedNames.push(value.name);
}
});
$('#dropdown1').change(function() {
$('#listbox').toggle(this.value != "");
});
$('#dropdown1').change(function() {
$('#listbox').empty();
$('<option>', {
text: 'Select your List Option',
value: '',
selected: 'selected',
disabled: 'disabled'
}).appendTo('#listbox');
var selection = $('#dropdown1 :selected').text();
console.log("as".selection);
$.each(jsObject, function(index, value) {
console.log("%o",value)
if (value['name'] == selection) {
var optionHtml = '';
for (var i = 1; i <=20; i++) {
var attr = 'attr' + ('000' + i).substr(-3);
var val = 'val' + ('000' + i).substr(-3);
optionHtml += '<option value="' + attr + '" data-val="'+value[val]+'">' + value[attr] + '</option>';
}
$("#listbox").css("width", "500px")
$("#listbox").css("height", "300px")
$('#listbox').append(optionHtml);
return false;
}
var selectedOption = $(this).find('option:selected');
console.log(selectedOption);
});
});
$("#listbox").on("click", function() {
console.log("asd", $('#listbox option:selected').attr('data-val'));
var zxv = $('#listbox option:selected').attr('data-val')
$(".bar").attr("y",zxv)
console.log("test", $(".bar").attr("y",zxv))
// $(".bar").attr("height",'100')
})
}
});
});
Hi Jasmin,
You can change the settings into Integer by following image.