PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 16, 2022

[FIXED] How to use script in same scripts twice on same page in opencart?

 October 16, 2022     html, opencart, php, script     No comments   

Issue

I am using the following script to show the barcode on the Invoice of my product SKU. But when I use the same script again to show the bar code for the product name{{ product.name }} and SKU barcode disappear, It only shows one barcode ie Product name barcode. How can I use the script to show multiple barcodes, for the product names and SKU?

FYI: I have no knowledge of codes.

<script src="https://cdn.jsdelivr.net/jsbarcode/3.3.20/JsBarcode.all.min.js"></script>
        <h1><img id="upc"/><script> $('#upc').JsBarcode("{{ product.sku }}",{width:1,height:50,lineColor: "#333333" }); </script></p></h1>

Solution

First I would say, learn how to use HTML, script and other code! Second (also said already), use correct code.

  1. add the script to your template (only once!), like:

<script src="//cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js"></script>

Do that at the end of the template.

  1. use correct HTML-Code, e.g.

<svg class="barcode" jsbarcode-format="code128" jsbarcode-value="{{ item.model }}"></svg>

beside each position the barcode shall be displayed.

  1. call the script and init it:

<script>JsBarcode(".barcode").init();</script>

at the end of your template.

  1. (optional): style your barcode output, according explained here: JSBarcode

p.s.: what I would do, is to store the jsbarcode script locally and call the local stored script.

I know many users intend to use cdn sources. Nice, but not effectful, imagine you want to diplay your solution locally without any internet connection. Or - think about the massive outfall a few weeks ago, where important sources were not reachable.

What you have, is what you can control!

pps: the difference in using a dot instead a # is, # indicates an ID, where the dot is simply a CSS-Class.



Answered By - OSWorX
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing