开发者

Passing Javascript variables in php [duplicate]

This question already has answers here: How do I pass variables and data from PHP to JavaScript? (19 answers) Closed 8 years ago.

I have 2 pages: details.php and terrainChooser.php

Terrain Chooser creates a td tag with an element and adds to it 3 input type="hidden" with information to retrieve.

window.opener.document.getElementById(elementID).innerHTML = "
<input readonly type='text' style='background-color:#eed8bb;border:0;' name='parcName" + parcNum + "' value=\"" + txt + "\" />
<input type='hidden' id='parcId" +parcNum + "' value='" + id + "' />
<input type='hidden' id='regID" + parcNum + "' value='" + regID + "' />
<input type='hidden' id='muni" + parcNum + "' value=" + muni +" />";

Inside details, they have been retrieved for a purpose and are used to display the values of the 3 input type hidden.

My question is, how do i go about using those javascript variables to say pass them through an sql statement in my php part say:

$SQL = "update T_TOURNOI_PARC set
F_PARCID1 = $parc[0],
WHERE F_TOURNOIINFOID = $tou开发者_开发百科rnoiId";
$rs->execute($SQL);

Where $parc[0] would have the 3 values.

This doesn`t work but is there something like this i can use?

<script type="text/javascript">
/* <![[CDATA */
var test = document.getElementById['muni1'].value
/* ]]> */
</script>
<?php
$test = ('<script type="text/javascript">test</script>');
?>


Javascript runs in the browser and is not connected to your PHP (which is on the server)

You need to send the data back to the server using AJAX.


You should put the inputs in a form and post them to another script to handle the parameters. Take a look at http://www.tizag.com/phpT/forms.php


Javascript runs in the browser, PHP runs on the server. PHP can insert Javascript code into the page as it's generated, but to get Javascript to send something back to PHP, you'll need to use AJAX.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜