Reputation: 167
I am getting an error on the first time telling me it has an unexpected identifier. I am unsure what is causing it, I am making a big string of code so users can copy and paste it to use on webpages.
var generatedCode = " \
init(); \
<script> \
function init() \
{ \
disableDraggingFor(document.getElementById('bitcoin')); \
disableDraggingFor(document.getElementById('litecoin')); \
disableDraggingFor(document.getElementById('peercoin')); \
disableDraggingFor(document.getElementById('namecoin')); \
} \
";
Heres what it looks like: http://pbrd.co/1jawPVZ
Upvotes: 0
Views: 93
Reputation: 13
var generatedCode = "\
\<script\> \
function init() \
{ \
disableDraggingFor(document.getElementById('bitcoin'));\
disableDraggingFor(document.getElementById('litecoin'));\
disableDraggingFor(document.getElementById('peercoin'));\
disableDraggingFor(document.getElementById('namecoin'));\
} \
init(); \
\<\/script\> \
";
Just missing a few escapes on the brackets. Also errors within the returned string. This will work for you though.
generatedCode value:
<script> function init() { disableDraggingFor(document.getElementById('bitcoin')); disableDraggingFor(document.getElementById('litecoin')); disableDraggingFor(document.getElementById('peercoin')); disableDraggingFor(document.getElementById('namecoin'));} init(); </script>
Upvotes: 0
Reputation: 11255
Your screen shows what your are using single quotes only. For generatedCode
use "
and for document.getElementById calling use '
. Or for generatedCode
use '
and for document.getElementById calling use "
. For more info read this snippet.
Also you need close <script>
tag and call init
in script tag:
var generatedCode = " \
<script> \
function init() \
{ \
disableDraggingFor(document.getElementById('bitcoin')); \
disableDraggingFor(document.getElementById('litecoin')); \
disableDraggingFor(document.getElementById('peercoin')); \
disableDraggingFor(document.getElementById('namecoin')); \
} \
init(); \
</script>";
OR
remove script
tag from your code if you call it in eval
for example (but better do not use eval):
var generatedCode = " \
function init() \
{ \
disableDraggingFor(document.getElementById('bitcoin')); \
disableDraggingFor(document.getElementById('litecoin')); \
disableDraggingFor(document.getElementById('peercoin')); \
disableDraggingFor(document.getElementById('namecoin')); \
} \
init();"
Upvotes: 1
Reputation: 1739
You are calling init()
function outside your <script>
tags, try placing it between <script>
and function init()
Upvotes: 0