在php onclick中传递Javascript值

在php onclick中传递Javascript值,php,javascript,Php,Javascript,下面是PHP代码,我需要在其中获取输入文本onblur的值 echo $script = "<script>"; $q = "select * from sp_documentocompra_detalle where dcd_codigo ='<script>document.getElementById('busqueda_de_producto').value;</script>'"; $res = mysql_query($q); $row = mys

下面是PHP代码,我需要在其中获取输入文本onblur的值

echo $script = "<script>";
$q = "select * from sp_documentocompra_detalle where dcd_codigo
='<script>document.getElementById('busqueda_de_producto').value;</script>'";
$res = mysql_query($q);
$row = mysql_fetch_array($res);
echo $script .= $row."</script>";
下面是包含输入文本的HTML代码

<input type='text' name='busqueda_de_producto' id='busqueda_de_producto' value='' onclick="text();"/>

您不能以这种方式使用Javascript写入PHP代码。在经典场景中,PHP源代码在将HTML和JS发送到客户端之前在服务器上编译和/或解释。在解释PHP代码之后,在浏览器中解释Javascript


可以使用PHP生成JS代码,但不能使用相反的方法。一旦Javascript获得所需的值,就必须通过页面加载或使用XMLHttpRequest对象发出某种HTTP请求,以便用PHP构建SQL查询,并将其传递给服务器。

您有PHP脚本,在视图文件中可以使用AJAX在单击时传递值

<script src="http://code.jquery.com/jquery-1.8.0.js"></script>
<script type="text/javascript">
    function text()
    {
        var textVal=$("#busqueda_de_producto").val();
        $.ajax(
        {
            type:"POST",
            url:"index.php",  //here goes your php script file where you want to pass value
            data: textVal,
            success:function(response)
            {
               //what to do in case of response
            }
        });

        return false;
    }
</script>
对于文本输入,执行如下操作

<input type='text' name='busqueda_de_producto' id='busqueda_de_producto' value='' onclick="javascript:text();"/>

它应该是$row['someindex']。;最简单的方法是使用$.post或$.get jquery的方法..只需使用搜索。你不是第一个问这个问题的人。只需使用搜索。它位于网站的右上角。如果你走到下面,就会看到相关的一栏。只要利用这些工具,在这个网站上发布的不仅仅是一个问题。例如,现有问题和答案。从index.php文件中,我如何使用Javascript中的变量输入文件的值通过POST请求传递。获取对$\u POST的访问权,这是您的值,获取它,确保安全性,因为它是从客户端传递的,并使用它