0% found this document useful (0 votes)
4 views

bar cade generating script

The document contains JavaScript functions for generating and scanning barcodes. The 'generateBarcode' function creates a barcode from a product name and price, while the 'scanBarcode' function retrieves and displays product details based on the scanned barcode. Both functions include input validation and display logic for user interaction.

Uploaded by

ravi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

bar cade generating script

The document contains JavaScript functions for generating and scanning barcodes. The 'generateBarcode' function creates a barcode from a product name and price, while the 'scanBarcode' function retrieves and displays product details based on the scanned barcode. Both functions include input validation and display logic for user interaction.

Uploaded by

ravi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

function generateBarcode() {

let name = document.getElementById("productName").value.trim();


let price = document.getElementById("productPrice").value.trim();

if (!name || !price) {
alert("Please enter both product name and price!");
return;
}

let barcodeData = `${name}-${price}`;

// Generate barcode but hide the encoded value


JsBarcode("#barcode", barcodeData, {
format: "CODE128",
displayValue: false, // Hides the encoded text
lineColor: "#000",
width: 2,
height: 50
});

// Show barcode
document.getElementById("barcodeContainer").style.display = "block";
}

function scanBarcode() {
let scannedCode = document.getElementById("scanInput").value.trim();
let details = scannedCode.split("-");

if (details.length === 2) {
document.getElementById("productDetails").innerHTML = `
<p><strong>Store:</strong> My Super Mart</p>
<p><strong>Product:</strong> ${details[0]}</p>
<p><strong>Price:</strong> $${details[1]}</p>
`;
} else {
document.getElementById("productDetails").innerHTML = "";
}
}

You might also like