Netbeans - Syntax Check error using php inside javascript
-
29-10-2019 - |
Question
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
Solution
edit your syntax to this:
isDisabled:<?php
if($_SESSION["rate_of_".$coObj->company_id] == 1)
echo 'true';
else
echo 'false';
?>,
OTHER TIPS
@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?!?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow