Javascript in Wordpress: "Uncaught SyntaxError: Unexpected token <" -


i trying call function part of external javascript file. following error in line 1 of .js file.

"uncaught syntaxerror: unexpected token < "

i following error:

"uncaught referenceerror: drawcolchart not defined".

drawcolchart name of function calling.

i calling drawcolchart function in functions.php file of wordpress. related code appended below:

<script type="text/javascript" language="javascript">  drawcolchart('inc_exp_chart');  </script> 

the javascript file follows:

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>     google.load("visualization", "1", {packages:["corechart"]});     google.setonloadcallback(drawcolchart);  function drawcolchart(divi) {     var data = google.visualization.arraytodatatable([       ['year', 'sales', 'expenses'],       ['2004',  1000,      400],       ['2005',  1170,      460],       ['2006',  660,       1120],       ['2007',  1030,      540]     ]);      var options = {       //title: 'company performance',       //haxis: {title: 'year', titletextstyle: {color: 'black'}},       vaxis: {title: 'rs (lacs)', titletextstyle: {color: 'black'}},       legend: {position: 'bottom'},     };      var chart = new google.visualization.columnchart(document.getelementbyid(divi));     chart.draw(data, options);     document.write('wow');   } 

i have enqueued javascript file in header.php. checked script enqueued using wp_script_is function.

any appreciated. have wasted 3 hours trying debug this.

you can't have script tag in file. script included script, not html. either put script tag in html page, or use javascript create script tag dynamically , add head element.

the syntax error comes script tag being parsed javascript. result nothing in file executed, function drawcolchart isn't created. when later try call it, error message it's not defined.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -