Posted by Hilarion on 09/30/05 17:53
> the following can be quite neat.
>
> <script>
> if( <?=( $something ? 'true' : 'false' )?> ){
> alert("Yes");
> }else{
> alert("No");
> }
> </script>
This one generates shorter HTML/JS and works the same way:
<script>
<?php if ($something) { ?>
alert("Yes");
<?php } else { ?>
alert("No");
<?php } ?>
</script>
This one is also more elegant:
<?php
if ($something)
$alert = 'Yes';
else
$alert = 'No';
?>
<script>
alert( "<?= $alert ?>" );
</script>
Hilarion
Navigation:
[Reply to this message]
|