My website cannot show the prices for different product options and I found the following error message on Chrome inspection:
Uncaught SyntaxError: Unexpected identifier
It is pointing to the line below:
var first_variant_price = $('ul li input[type='radio']:checked').attr('data-price');
This is the complete script:
<script type='text/javascript' charset='utf-8'>
$(document).ready(function(){
var first_variant_price = $('ul li input[type='radio']:checked').attr('data-price');
$('.current-price').text( first_variant_price );
$('input[type='radio']').click(function() {
var variant_price = $(this).attr('data-price');
$('.current-price').text( variant_price);
});
});
</script>
I could not realize any mismatch on this code. Thanks for the help!
To solve the "Uncaught SyntaxError: Unexpected identifier" error, make sure you don't have any misspelled keywords, e.g. Let or Function instead of let and function , and correct any typos related to a missing or an extra comma, colon, parenthesis, quote or bracket.
The "Uncaught SyntaxError Unexpected end of input" error occurs for 3 main reasons: Forgetting a closing parenthesis, bracket or quote. Trying to parse an empty response with JSON.
If you use quotes inside other quotes, either use a different type or escape them:
$("ul li input[type='radio']:checked") // different type of quotes
or
$('ul li input[type=\'radio\']:checked') // escape inner quotes via backslash
but the easiest way is to not quote the radio
at all - it's not necessary.
$('ul li input[type=radio]:checked')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With