BruceyBandit
BruceyBandit

Reputation: 4324

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

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

Upvotes: 2

Views: 1124

Answers (5)

scartag
scartag

Reputation: 17680

You can convert it into a javascript variable (jquery framework helps with DOM manipulation)

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

var myVar = '<?php echo $postduration ?>';

Upvotes: 2

redmoon7777
redmoon7777

Reputation: 4526

var durationChosen = "<?php echo $_POST['durationChosen']?>";

Upvotes: 4

Dipu Raj
Dipu Raj

Reputation: 1884

It is simple as...

var myVar = '<? echo $postduration; ?>';

Upvotes: 2

DaveRandom
DaveRandom

Reputation: 88677

<script type="text/javascript">
  var postDuration = '<?php echo $_POST['durationChosen']; ?>';
</script>

Just echo it into the Javascript on the page, just like any other dynamic content.

Upvotes: 3

RomoCode
RomoCode

Reputation: 1119

Yep, of course!

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

Kinda like this:

<script>
    var myVar = <? echo $postduration; ?>;
</script>

Upvotes: 7

Related Questions