I’m writing a page that will print badge labels for members. It’s a DYMO labelmaker, and I’m using their javascript label framework.
All the members are listed with checkboxes, with the data to be encoded for the badge in the value. The user will check the members they want to print badges for, and click print.
The script will grab the checked checkboxes, which it does, and pass the value through a get request to a separate php file that will return the encoded data, and it does.
The data to be returned is period delimited, which I need to split and put each piece on a separate line. The problem is I can’t seem to get the data out of the scope of the get.
The pertinent portion of the script:
printButton.onclick = function() {
try {
printButton.disabled = true;
settings.currentPrinterName = printersComboBox.value;
var printer = printers[settings.currentPrinterName];
if (!printer)
throw new Error("Select printer");
var label = null;
if (printer.printerType == "LabelWriterPrinter") {
label = addressLabel;
}
if (!label)
throw new Error("Label is not loaded. Wait until is loaded or reload the page");
var labelSet = new dymo.label.framework.LabelSetBuilder();
var barcode
$("#memchk :checked").each(function(){
var value = $(this).val();
var barcode;
var record = labelSet.addRecord();
$.get("http://ranch/sunrise/wolf/plugins/member_directory/views/barcode.php",{encString: value}, function(data){
//alert(data.split("."));
barcode = data.split(".");
});
alert(barcode[0]);
record.setText("TEXT", barcode[0]);
record.setText("TEXT_1", barcode[1]);
record.setText("TEXT_2", barcode[2]);
record.setText("TEXT_3", barcode[3]);
record.setText("TEXT_4", barcode[4]);
record.setText("TEXT_5", barcode[5]);
record.setText("TEXT_6", barcode[6]);
record.setText("TEXT_7", barcode[7]);
record.setText("TEXT_8", barcode[8]);
var memName = value.split("^");
record.setText("TEXT_9", memName[0]);
});
//label.print(printer.name, null, labelSet.toString());
saveSettings();
} catch(e) {
printButton.disabled = false;
alert(e);
}
printButton.enabled = true;
}
I’ve tried setting the text for each line inside the get, but it doesn’t take. The alert inside the get displays the expected data, but if i try to run it as it, it says barcode is undefined. If I comment out the get and set the text lines of the label to static strings, it works fine.
Why can I not get the data?
instead of get, try this:
and you’ll have barcode assigned with your request, and this:
should work 😉