Pro custom javascript function causing javascript error

Hello,

I’m having a problem with custom javascript needed for my Formidable Form not working on my site. I reached out to Formidable Forms support and they told me that the javascript error was coming from the Pro theme custom javascript function. You can see their response below. The page the error is on is https://agentmatch.realty/selling. How do I fix this javascript error? Thanks!

Hi R,

It looks like it may be something unrelated. I’m seeing this javascript error on your page:

Uncaught SyntaxError: Unexpected token <
Javascript errors can prevent other javascript from working on the page. So you’ll need to find out where this error is coming from.

It looks like it is coming from whatever is adding this:

<script id="cornerstone-custom-content-js" type="text/javascript">//
// No need to add script tags
// here; simply get started
// by writing JavaScript!
// Remember to save your
// changes to see them :)
//
</script><script id="x-customizer-js"><script type="text/javascript">

Did you add a plugin that makes it unnecessary to add script tags?

Hello There,

Thanks for posting in! I have checked you site and visited most of the site pages. I do not see any JS errors on the page. Does the error only appear when you insert a JS code? Could you please insert the JS code in your next reply?

Please be advised that when you insert a JS code, it should not contain any <script> tags because the output is already wrap with <script> tag. having that tag in your custom JS code will definitely create a JS error Uncaught SyntaxError: Unexpected token <.

Hope this helps.

Hi. Thanks for your reply. I am inserting the javascript into the Formidable Form plugin directly. It is as follows:

<script type="text/javascript">
jQuery(document).ready(function($){
$("#field_gn8ly").change(function(){
var n = $("#field_gn8ly").val();
n = numberWithCommas(n);
if(n == "2,000,000") n += "+";
$(".frm_range_value").text("$" + n);
$(".frm_range_value").change();
});
const numberWithCommas = (x) => {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
});
</script>

It does not work unfortunately, although it used to before I removed it from the Cornerstone javascript editor because I had included the script tags and it was showing an error, although it worked. When I try and put it back in the cornerstone javascript editor with our without script tags it does not work.

Here’s the support thread from Forimdable Forms: https://agentmatch.realty/wp-content/uploads/2018/05/screencapture-formidableforms-help-desk-format-slider-value-as-currency-2018-05-06-19_30_44.png Thanks!

Hello There,

When you insert this code in the Theme Options custom JS section, please use this code:

</script><script type="text/javascript">
jQuery(document).ready(function($){
$("#field_gn8ly").change(function(){
var n = $("#field_gn8ly").val();
n = numberWithCommas(n);
if(n == "2,000,000") n += "+";
$(".frm_range_value").text("$" + n);
$(".frm_range_value").change();
});
const numberWithCommas = (x) => {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
});

Please let us know how it goes.

Hi RueNel,

Unfortunately it still does not work.

Hello Roman,

I can see that you already added the script as I instructed and there are no longer any JS errors in the page.

Do you mean that the code is not working for you? Please contact the creators of the script. They might have a clue why their script is not working.

Please let us know how it goes.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.