根据javascript值更改php变量 [英] Change php variable based on javascript value

查看:115
本文介绍了根据javascript值更改php变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据JavaScript变量将值更改/分配给php变量? 这是我的代码.

how can i change/assign a value to php variable depending on a javascript variable? here is my code.

<select id="reOutcome" name="reOutcome" onchange="OnChange(this.form.reOutcome);">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
</select>

<script type="text/javascript">

function OnChange(dropdown)
{
    var myindex  = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value
    if(SelValue==2){        
     <?php
    $sCOMPFields .= "|"."SreComments";
    $sCOMPFields .= "|"."rePrID";   
     ?>
    }
    return true;
}
</script>

onchange功能运行正常.我只是不知道如何更改php变量.我在网上搜索了很多.即时通讯是如何将php变量分配给javascript.那不是我想要的. 感谢您的帮助.

The onchange function is working fine. I just don't know how to change the php variable. I searched online a lot. All im getting is how to assign php variable to javascript. That is not what im looking for. Thanks for your help.

推荐答案

您想要的执行不会发生,因为php作用域和javascript作用域的流发生在不同的时刻.是这样的:

The execution you want won`t occur, because the flow of the php scope and the javascript scope occurs on different moments. It is something like this:

因此,当通过浏览器在用户计算机上执行javascript时,您将无法执行php,但可以在服务器上执行php来生成需要在用户计算机上执行的javascript.

So, you can`t execute php while the javascript is being executed on the computer of the user through the browser, but you can execute php on your server to generate the javascript you need to be executed on the user computer.

实际上,您的问题似乎更接近于什么是最好的方法(某事)"

Actually, your question seems to be closer to a "what is the best way to do (something)"

这篇关于根据javascript值更改php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆