PDA

View Full Version : Problem adding javascript to template


derfelix
18 Nov 2009, 11:39
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..

Paul M
18 Nov 2009, 13:15
It is a known bug in the template parser.

derfelix
18 Nov 2009, 14:58
thanx
for your reply
Felix

Lionel
21 Nov 2009, 18:24
surround the javascript with

<vb:literal>

your script

</vb:literal>

derfelix
21 Nov 2009, 19:00
thx
works!