tags:

views:

44

answers:

3

so in such situation you lose the javascript highlight syntax, to me it looks like there are some cases were youre obliged to put the Js in a php string (for example when working on some ajax stuff and php mysql request), how you do? i found very annoying to work js this way

echo '<script>
$(function(){
$("select#discipline_").change(function(){
  var selected = $("select#discipline_ option:selected");

$.ajax({
        url: "valider.php?discipline_val="+selected.val()+"&action=specialite",
        success: function(response){
          $("span#specialite").html(response)
      if( selected.val()=="0" ){
                $("select#specialite_").hide()
                $("span#add").hide()
              }
         else{
           $("select#specialite_").css({width:"0px"}).animate({width:"204px"}, 300).fadeIn()
              $("#add").show()
         } } } ) } )

 })</script>';
+1  A: 
<?php if($a==1){ ?>  
    <div id="helloDiv">hi</div>  
<?php } ?>
Luis Junior
+2  A: 

Generally, it is really preferable to keep large blocks of JavaScript in a separate file.

This also forces one to keep a tidy structure in the JavaScript - splitting things into functions and classes - which is a good thing.

If you are in the PHP body, you can easily break out to HTML:

... PHP code ....
?> 

<script>
 ... Javascript code
</script>

<?php 
... PHP code ....
Pekka
As long as the function encloses the entire 'break' in PHP code, it would still work correctly (as the op echo's STDOUT is good enough)
Wrikken
A: 

Like Luis mentioned, that's the best way to do it unless you want to ad \ in front of all ' and "

VisBits