Helpful Information
 
 
Category: vB4 Programming Discussions
Problem adding javascript to template

Hello

Might be a bug (but couldnt find the bug reporting stuff on vbulletin.com)
But probably its just stupid me.. that cant write javascript...

I want to edit a template (any template) and add a simple javascript:

<script type="text/javascript">
function checkme()
{
var test='test';
}
</script>

And it gives me
Parse error: parse error in C:\apache\apache2\htdocs\xxx\forums\includes\adminfunctions_template.php(4516) : eval()'d code on line xx

when i remove the var test="test"; line, the template saves perfectly..
if i add javascript other than var x = ''; or something.. it works...
I could write var test="test"; outside of the function... that works... but no point in having a function then...



i found the parse error in adminfunctions_template.php on line 4516 it does
eval($template)
so i added ... print $template;exit;
and on that line it does:
function checkme()
' . htmlspecialchars($test=test;) . '
which gives the parse error...

Now my question. Is there a simple way to add my function?

thanks for any help

Felix



Found a workaround, not very elegant.. but works for me... maybe it helps someone else..
<script type="text/javascript">
function checkme()
{
var test='test';
}
</script>
Gives a template parse error...
but:
<script type="text/javascript">
var test='';
function checkme()
{
test='test';
}
</script>

works...
seems that the parse error is triggered by the var inside a function... strange..

It is a known bug in the template parser.

thanx
for your reply
Felix

surround the javascript with

<vb:literal>

your script

</vb:literal>

thx
works!










privacy (GDPR)