PDA

View Full Version : Problem adding javascript to template


derfelix
11-18-2009, 09:39 AM
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\admin functions_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
11-18-2009, 11:15 AM
It is a known bug in the template parser.

derfelix
11-18-2009, 12:58 PM
thanx
for your reply
Felix

Lionel
11-21-2009, 04:24 PM
surround the javascript with

<vb:literal>

your script

</vb:literal>

derfelix
11-21-2009, 05:00 PM
thx
works!