Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I convert a php $_POST variable into a jquery variable?

Tags:

jquery

php

I want to know can I convert a php $_POST variable into a jquery variable. I have php variable below:

<?php  $postduration  = $_POST['durationChosen']; ?>

Can I convert the php variable above into a jquery variable?

Thanks

like image 839
BruceyBandit Avatar asked Feb 13 '26 15:02

BruceyBandit


2 Answers

Yep, of course!

Just write/output your PHP code right into your JavaScript ... block.

Kinda like this:

<script>
    var myVar = <? echo $postduration; ?>;
</script>
like image 128
Romanulus Avatar answered Feb 15 '26 06:02

Romanulus


var durationChosen = "<?php echo $_POST['durationChosen']?>";
like image 35
redmoon7777 Avatar answered Feb 15 '26 07:02

redmoon7777



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!