<script> <!-- ... --> <?php if(!$recibida) echo "document.getElementById('recibida2').value = value;"; ?> <!-- ... --> </script>