Can't use javascript on any of my pages. It simply does nothing.

Solved
Highlighted
Tourist
5 1 0

So I'm attempting to embed a javascript calculator I made on another website which provides embedding code, but no matter where I insert the code it doesn't work and nothing shows up. For example, I created a new page template and insert the following code straight into the .liquid. But when I load the page, nothing shows up.

 

 

<div class="calconic-calculator"  data-calculatorid="5f581874a6a5010029339863"></div>
<script>
  (function() { var qs,j,q,s,d=document, gi=d.getElementById,
  ce=d.createElement, gt=d.getElementsByTagName,
  id="calconic_", b="https://cdn.calconic.com/static/js/";
  if(!gi.call(d,id)) { j=ce.call(d,"script"); j.id=id; j.type="text/javascript"; j.async=true;
  j.dataset.calconic=true;
  j.src=b+"calconic.min.js"; q=gt.call(d,"script")[0]; q.parentNode.insertBefore(j,q) }
})();
</script>

 

0 Likes
Highlighted
Shopify Partner
62 5 14

What is the error you are getting on the console?

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes
Highlighted
Tourist
5 1 0

I seem to be getting a few errors even on other pages, so I'll do my best to try and find the relevant errors relating to the javascript. I'm seeing the following:

 

calconic.min.js:1 SyntaxError: Unexpected end of JSON input
    at calconic.min.js:1
    at u (calconic.min.js:1)
    at Generator._invoke (calconic.min.js:1)
    at Generator.forEach.e.<computed> [as next] (calconic.min.js:1)
    at a (calconic.min.js:1)
0 Likes
Highlighted
Shopify Partner
62 5 14

This is an accepted solution.

I'd suggest going back to the company that you got that code from.

If you are getting a Syntax error, that means there is an issue with the code you've been provided, (unless you edited it, in which case go and get the original code again!)

 

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes
Highlighted
Tourist
5 1 0

Weird thing is, though, is that no javascript code is working anywhere on my site, even if I write something simple like 

<script>
  function myFunction() {
  return "Hello";
}
    </script>
0 Likes
Highlighted
Shopify Partner
62 5 14

That code won't do anything anyway......

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes
Highlighted
Shopify Partner
62 5 14

Here is a basic Javascript you can try. Click the button, the number will change from 1 to 2

<html>
<div>
    <input id="InputField">
</div>
  <button class="btn" onclick="changevalue()">1</button>
<script>

     function changevalue(){
          document.getElementById("InputField").value = 2;
          return true;
        };
</script>
</html>

 

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes
Highlighted
Tourist
5 1 0

This is an accepted solution.

Sorry, forgot to mention I had a way to call the function to make it execute. Yeah, somethings seems off about javascript on my website.

0 Likes
Highlighted
Shopify Partner
62 5 14

Its unlikely, but it could be.

Don't forget just returning "Hello" in JS has no effect. If you want to print it to the console you need to do console.log("Hello")

If you still think its your specific website, it might be worth hiring a Shopify Expert to fix it up for you.

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes