I'm writing a personal hta (I know it's old), but having an issue with the last part. I have a local file which I'm populating an array with; then I have check boxes which are checked based on the values read from the file. The part I'm having an issue with is getting the check boxes to check with the array when loaded from the file.
I have a separate div which I'm also populating with text from what's read from the file, and it's working correctly. If I copy that text and manually add it to the array, the check boxes are checked as expected. It just won't do it based on the file loading the array.
function readTextFile(file) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.OpenTextFile("C:/users/passi/desktop/test2.txt", 1)
var output = fh.ReadAll();
var arr = output;
return arr;
}
var arr = readTextFile();
var array = [arr];
function loadArray() {
alert(array); \\to verify the array contains the expected text
$('#tst').text(array); \\to populate a test div as a second check the array is correct
$("#cbform :checkbox[type='checkbox']").each(function(){
if($.inArray($(this).val(),array)!=-1){
$(this).prop("checked",true);
} else {
$(this).prop("checked",false);
}
});
}
Aucun commentaire:
Enregistrer un commentaire