var props = {};
$.ajax({
url: 'https://randomuser.me/api/',
dataType: 'json',
success: function(data){
var user = data.results[0].user,
list = $('.form-control'),
prop;
deepSearch(user);
for (var i = 0, len = list.length; i < len; i += 1) {
prop = props[ $(list[i]).attr('id') ];
if ( prop ) $(list[i]).val(prop);
}
}
});
function deepSearch(node) {
for (var elem in node) {
if ( typeof node[elem] !== 'object' || isObjectEmpty(node[elem]) ) {
props[elem] = node[elem];
} else {
deepSearch(node[elem]);
}
}
}
function isObjectEmpty(obj) {
for (var key in obj) {
return false;
}
return true;
}
$("input[type=text]").each(function() {
var input = $(this), id = this.id;
input.attr('name', id);
});
<span id="nextLabel">SLPK</span>
<input type="text" value="3" data-label="minSl" name="min_bedrooms" class="form-control" placeholder="Typ of selecteer..." data-original-title="" title="">
<input type="text" value="4" data-label="maxSl" name="max_bedrooms" class="form-control" placeholder="Typ of selecteer..." data-original-title="" title="">
diff = function (a1, a2) {
return a1.filter(function(i) {return a2.indexOf(i) < 0;})
.concat(a2.filter(function(i) {return a1.indexOf(i) < 0;}))
}
compare = function (a1, a2) {
return a1.length == a2.length && a1.every(function(v,i) { return v === a2[i]})
}
var equalArrays = function (array, compareArray) {
var i, len = array.length;
if (len !== compareArray.length) {
return false;
}
for (i = 0; i < len; i += 1) {
if (array[i] !== compareArray[i]) {
return false;
}
}
return true;
};
$(".ajaxcart").colorbox({
onLoad : function() { $(this).colorbox.resize(); },
onComplete : function() { start_show(); $(this).colorbox.resize(); },
fastIframe: false,
scrolling: false,
initialWidth: false,
innerWidth: false,
maxWidth: false,
height: false,
initialHeight: false,
innerHeight: false,
//returnFocus: false,
top: '45%' <- убрать