Setting Values from array
Hi,
I have a dropdown and 2 labels in my aspx page. I am trying to fill the dropdown and the label using jquery.
I have used the below code:
- //Declared Globally
var testarray = [];
var fileDescription = "";
var imagePath = "";
var Title ="";
- $(document).ready(function () {
while loop //values added to each item
{
testarray.push(Title) + "$~@" + imagePath + "$~@" + fileDescription);
}
SortArray();
});
- function SortArray() {
var ddlImg = this.document.getElementById("ddlImages");
ddlImg.options.length = 0;
if (testarray.length > 0) {
- testarray.sort(function (a, b) {
var a1 = a[1], b1 = b[1];
if (a1 == b1) return 0;
return a1 > b1 ? 1 : -1;
});
- for (var i = 0; i < testarray.length; i++) {
var newArray = testarray[i].split('$~@');
for (var j = 0; j < newArray.length; j++) {
ddlImg.options[ddlImg.options.length] = new Option
- (newArray[j], newArray[j]);
fileDescription = newArray[j];
imgfilename = newArray[j];
$(".Imageholder").attr("src", imgfilename);
}
}
}
}
each item in array would be like the above one. It can also have null in the 2nd and 3rd.
I am trying to sort the data and assign the first value in dropdown, 2nd value in image holder, 3rd value in file description. Split is based on "$~@"
Example data:
How to fix this?
Thanks