2

Im getting an error that there is a syntax problem on the line where selection = ui.item.addClass etc.. , but I can't figure out what it is. I think I have escaped all the right quotes but I'm not sure. note: the first two variables are meant to contain empty single quotes.

<?php      
echo    "<script>";

echo    "$(function(){";


echo  "var selection = \' \'; ";

echo  "var selectClass = \' \'; ";

echo  " $(\".menu\").menu({ ";

echo  " select: function (event, ui) { "
echo   " $(\'.selected\', this).removeClass(\'selected\'); ";
echo     "  selection = ui.item.addClass(\'selected\').children(\'a\').attr(\'name\');";


echo  " }"; // closes select function

echo  "  }); "; // closes menu
echo  " </script>";
?>
4
  • What is the point in the javascript output being echo ;? Why don't you just drop out of your PHP tags then drop back in? Commented Apr 6, 2013 at 22:14
  • you dont need to escape ' within a " - a plain 'select' would work Commented Apr 6, 2013 at 22:15
  • better yet why are you mixing javascript with php? separate the logic Commented Apr 6, 2013 at 22:16
  • This is just something I'm trying out. I'm not sure if I will keep it, but right now mixing javascript and php is the best way I know how to get a javascript variable to another page within all the other code I'm using. Commented Apr 6, 2013 at 22:41

4 Answers 4

6

First I shall simplify your code:

<?php      
echo  <<<'SCRIPT'
<script>
$(function(){
    var selection = ' ';
    var selectClass = ' ';
    $(".menu").menu({
        select: function (event, ui) {
            $('.selected', this).removeClass('selected');
            selection = ui.item.addClass('selected').children('a').attr('name');
        } // closes select function
    }); // closes menu
}); // close function()
</script>
SCRIPT;
?>

You will find this "magically" fixes your problem because now you don't have the missing semicolon ;)

Sign up to request clarification or add additional context in comments.

Comments

4

Personally. I'd drop out of the tags for my Javascript.. When I have finished typing, I see no harm in re-opening PHP tags to continue..

 //Other code here 
?>
<script>
$(function(){


var selection = ' ';

var selectClass = ' ';

$(".menu").menu({

select: function (event, ui) { 
$('.selected', this).removeClass('selected');
selection = ui.item.addClass('selected').children('a').attr('name');


}// closes select function

});// closes menu
});// closes function()
</script>

<?php 
// Continue here 

?>

Comments

1

You are missing a semi-colon in line #14

echo  " select: function (event, ui) { ";
echo   " $(\'.selected\', this).removeClass(\'selected\'); ";

Fixing which gives this: http://eval.in/15236

<script>$(function(){var selection = \' \'; var selectClass = \' \';  $(".menu").menu({  select: function (event, ui) {  $(\'.selected\', this).removeClass(\'selected\');   selection = ui.item.addClass(\'selected\').children(\'a\').attr(\'name\'); }  });  </script>

Comments

0

in last line add this

echo  "  }); "; // closes menu
// --- add this
echo " });";
// -----
echo  " </script>";

try it :D

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.