I would like to pass a var from PHP to Javascript. I did this but it does not work. Can someone help me? If you tell me where I'm wrong I learn.
<script>
var passo = <?php echo 'hello'; ?>;
</script>
<button type="button" onclick="funzionepassaggio(passo)" class="btn btn-info btn-lg" data-toggle="modal" data-target="#ModalSubmit"><?php echo "empty"; ?></button>
<script>
function funzionepassaggio(pass) {
alert("hello" + pass);
}
</script>
The answer is hello undefined.
I have one other question! The variable that I have to pass is located within a loop, and of course he always passes the last value! How can I do so that has passed the value that the variable at that time? This is the code:
for ($a = 0; $a < 2; $a = $a + 1) {
?>
<td>
<script>
var passo = "<?php echo $rigauno->nome; ?>";
</script>
<button type="button" onclick="funzionepassaggio(passo)" class="btn btn-info btn-lg" data-toggle="modal" data-target="#ModalSubmit"><?php echo "vuoto"; ?></button>
</td>
<?php } ?>
onclick="funzionepassaggio(<?php $phpVariableHere ?> )"