php - Uncaught syntax error: Unexpected token in Wordpress button function -
this 1 of functions made in wordpress site button open shortcode pop prompt. saw <p>
tags added wordpress inside function, maybe error in.
<input id="textarea" name="textarea" type="text" value="" placeholder="place here"> <script> function pol() { var x; var name=prompt("name","name"); if (name!=null) { x = document.getelementbyid("textarea").value; x = "[pol]" + name + "[/pol]"; document.getelementbyid("textarea").value=x; } } </script> <input type="button" value="pol" onclick="pol()">
errors:
uncaught syntax error: unexpected token < uncaught referenceerror: pol not defined
in wordpress page, on chrome, inspect element shows function this:
<input id="textarea" name="textarea" type="text" value="" placeholder="place here"></p> <p><script> function pol() { var x;</p> uncaught syntaxerror: unexpected token < <p>var name=prompt("name","name");</p> <p>if (name!=null) { x = document.getelementbyid("textarea").value; x = "[pol]" + name + "[/pol]"; document.getelementbyid("textarea").value=x; } } </script></p> <p><input type="button" value="pol" onclick="pol()"></p> uncaught referenceerror: pol not defined (repeated 2 times)
i discovered theme source of errors. somewhere conflict...
solution:
in every empty line, wordpress theme coded ad <p>
tags, , made errors, fixed function , working:
<script> function pol() { var x; var name=prompt("name","name"); if (name!=null) { x = document.getelementbyid("textarea").value; x = "[pol]" + name + "[/pol]"; document.getelementbyid("textarea").value=x; } } </script> <input type="button" value="pol" onclick="pol()">
you can add following code in php page remove wordpress pre-coded
tags every new or empty line. remove_filter('the_content', 'wpautop');
Comments
Post a Comment