Issue
<form>
<?php
echo
"<script>
quant = $item_quant;
</script>";
?>
<input type="number" name="quant" class="quant" placeholder="{{ quant }}">
</form>
I tried using "{{ quant }}" but the numbers initially flicker and don't display. I'm basically setting script variable quant to equal php variable $item_quant and then making html input placeholder to equal the value of quant. Any ideas? Thank you so much.
Solution
That is not how JS (or HTML) works.
You do not need JS here
<form>
<input type="number" name="quant" class="quant" placeholder="{{ $item_quant }}">
</form>
or
<form>
<input type="number" name="quant" class="quant" placeholder="<?= $item_quant ?>">
</form>
If you insist on JS, then this. Note the placeholder will contain a PHP string in this snippet until you put it on your server
<?php ... ?>
<script>
const quant = `<?= $item_quant ?>`;
window.addEventListener('DOMContentLoaded', () => {
document.querySelector('.quant').placeholder = quant;
});
</script>
<form>
<input type="number" name="quant" class="quant" placeholder="">
</form>
Answered By - mplungjan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.