How to use the JAVASCRIPT_FUNCTION Component

Last updated: Sep 4th 2021

Barcode to PC allows you to manipulate the barcodes and the variables by executing JavaScript code.

Examples of what you can do with this component

  • Remove the first n characters from the barcode
  • Remove the last n characters from the barcode
  • Replace parts of the barcode
  • Extrapolate the data encoded inside the barcode

and the list goes on and on, you can use pretty much any combination of JavaScript methods to manipulate the strings. You can find the full list here.


Step 1 – Add the JAVASCRIPT FUNCTION Component
To do that, Drag & Drop the component from the Available components field to the Output components field by keeping pressed the left mouse button.

Step 2 – Write the JavaScript Function
Click on the component that you just added, and type the function that you want to be executed inside the JavaScript field.

Step 3 – Add variables
Every time you use a variable inside the JavaScript field you’ll have to insert a corresponding Output Component that will assign a value to that variable.

For example if you use the barcode variable, you’ll have to insert also a BARCODE component in the Output template field, otherwise, if you don’t do that the JavaScript component will fail and won’t be executed properly.

To prevent the BARCODE component affecting the Keyboard Emulation output you can click on it and enable the Skip output option.


Example 1
Let’s say that you want to remove the first character of the barcode

Initial barcode: 0897654321
Final output: 897654321

Follow these steps:

  • Add a JAVASCRIPT FUNCTION component just after the BARCODE component
  • Add this code in the JavaScript field: barcode.substr(1).
  • Enable the Skip output option of the BARCODE component

Example 2
Extrapolate parts of the barcode

Initial barcode: 433-0132-22
Final output: 0132

Use the same procedure of Example 1, but use this JavaScript code instead: barcode.split('-')[1]

Example 3
Replace a specific part of the barcode

Initial barcode: first_name:john;last_name:doe
Final output: name:john doe

Use the same procedure of Example 1, but use this JavaScript code instead: barcode.replace('first_name:','name:').replace('last_name:', ' ')

Tip 1: to remove a specific part of the barcode you can use the replace() method, and pass an empty string as second parameter, for example: barcode.replace('a', '')

Tip 2: you can use a regular expression as first parameter, for example barcode.replace(/w/gi, '') will perform a global, case-insensitive replacement of the w character.

Example 4
Extract a parameter from an URL

Initial barcode:
Final output: RN015215156

Use the same procedure of Example 1, but use this JavaScript code instead:
new URL(barcode).searchParams.get('tracking_id')


  1. Is it possible to create a menu to scan information from different sections of the warehouse or different pallets?

  2. I have writen a couple of JavaScript functions so that I can work out the human-readable text in the barcode Brazilian banks generate and I’m trying to use your app and server to “type” the code to the bank site. Problem is I can’t implement those functions in the JS FUNCTION component or, at least, I don’t know how! I can send my code for analysis or maybe get a few tips on ways to put more complex functions in the component. Thanks in advance!

  3. Como puedo hacer que los resultados del escaneo, salgan en diferentes columnas del Excel.

    Ahora mismo tengo todo en una misma casilla.

    Muchas gracias de antemano

  4. Hola Como puedo hacer para llenar un formulario web con el resultado del escaneo de un pdf417 con el siguiente formato.

  5. In my company the CRM export a file .txt, and we need to put on the cellphone (or the barcode server) and make the Android to read a barcode on the tag and compare with this file, it is possible?
    In meanwhile this document necessery to unique barcode for all document, let me try to explain example , barcode 1234 insert and when the person scan 1234 again he has the message its equal and don’t copy, it’s possibly too?

  6. Hi,
    Is it possible to read the QR code and run the printing program? Then execute “command + P” (print)? All in one read QR code.

  7. Hi
    I work in Pharmaceutical industry and recently in Europe they introduced SecurPharm Symbology
    I do not have any programming knowledge so i have been reading around various articles untli i found yours amazing tecnology.
    So Basically i have a need to store Captured Barcodes in text only to input them at a later time in a webpage for validation. I cannot though emulate those special characters like , , , , ,
    Is there a workaround ?
    Many thanks in advance

  8. Hi, how can I save barcodes into a database? I’m using phpmyadmin and I want to retrieve the data in my sales inventory website in PHP

    1. You could use the RUN component to execute SQL queries, see: How to use the RUN Component

      You can create your own script with a language you’re familiar with ​or if the query is simple enough you can use a command like this:


      mysql -u USERNAME -pPASSWORD -N -B -e "INSERT INTO products ... ;"


      output template

      Note: there isn’t space between the -p parameter and the password

  9. How can I extract two different variables with the same name? For example, I want to get “select_option” twice with different values but when I get them it just appear the last value of the last “select_option”

Your email address will not be published. Required fields are marked *

Related posts