我想将 JavaScript 变量的值设置为 PHP 变量。怎么才能做到这一点?
请给我一些建议。
我的代码是:
document.getElementById("dummy").value= <?php echo ("document.getElementById('txtplan').value"); ?> //document.formn.txtplan.options[document.formn.txt'+fld+'.selectedIndex].value //eval(''); $_POST['txtplan']
alert(document.getElementById("dummy").value);
<?php
$planname = $_POST["dummy"];
$plandetails = mysql_query("SELECT * FROM membershipplan where planname='$planname'");
while($row1 = mysql_fetch_array($plandetails))
{?>
document.getElementById("txtduration").value=<?php echo $row1['planduration']; ?>
document.getElementById("txtplancontact").value=<?php echo $row1['plannoofcontacts']; ?>
document.getElementById("txtplanamount").value=<?php echo $row1['planamount']; ?>
<?php
}
?>
});
我不喜欢这种方式,请给我上述过程的替代方法
最佳答案
JS -> PHP = impossible (only if you send that info to PHP using POST or GET)
PHP -> JS = possible var text = <?php echo( $text ); ?> ;
唯一的原因是 PHP 代码是在您的服务器上执行的。
关于javascript - 将 JavaScript 变量的值设置为 PHP 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19853052/