1

Netbeans 7.0 is highlighting lines as syntax error when i use PHP inside JavaScript

In my case

<script type="text/javascript">
$(document).ready(function(){
    $("#rating_<?=$coObj->company_id?>").jRating({
        step: true,
        longStarsPath:"include/jrating/jquery/icons/btn_black_trans2.png",
        rateMax:1,
        phpPath:"include/jrating/php/jRating.php",
        <?php
        if($_SESSION["rate_of_".$coObj->company_id] == 1)
            echo 'isDisabled: true,';
        else
            echo 'isDisabled: false,';
        ?>
        type:'long',
        length : 1,
        decimalLength : 0,
        rateMax: 1,

        onSuccess : function(){
            alert('Success : your rating has been saved');
            location.reload(true);
        },
        onError : function(){
            alert('Error : please retry');
        }
    });
});
</script>

all the lines below PHP code are highlighted, and first line says that missing : after property id

2 Answers 2

3

@Marek: I don't really see that as an answer, more of a workaround (which doesn't always work)...

NetBeans should make things easier, not make us change syntax to avoid it failing in the highlighting...

Anyways, I use a lot of mixed Javascript/PHP code, and NetBeans fails miserably all over the place...I also use Notepad++ which doesn't have any problems with this...

Example:

function showUpload<?php echo $upload_number;?>(file) { /*some code*/ }

Or:

$('.option-help').qtip({
    content: function(api) { return $(this).parent().attr('data-tip'); },
<?php if ($option_help == 'icon') { ?>
    show: { event: 'click' },
<?php } ?>
    position: {my: 'bottom left',at: 'top left'}
});

Does anyone know of a better solution to the OP's question?!?

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

Comments

1

edit your syntax to this:

isDisabled:<?php
    if($_SESSION["rate_of_".$coObj->company_id] == 1)
        echo 'true';
    else
        echo 'false';
    ?>,

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.