javascript - 在输入 html 表单上从 java 脚本传递参数

标签 javascript php jquery html

我在将 javascript 变量作为 html 表单上的输入隐藏类型的值传递时遇到问题。

了解更多详情:

  public function exportToPdf1($headerText=""){

    // serialize the grid object into the session
    $_SESSION[$this->viewPaneId."-pdf"] = serialize($this);


    $pfdExport .= ' // create the export to pdf button
    $("#'.$this->getViewPaneId().'").prepend("<div id=\"pdfExport\"       style=\"float:right; border: none; cursor:pointer;\"><img src=\"images/stock_save_pdf.png\"> </div>");';

    $pfdExport.=' // onClick function
             var printToPdf = false;
             var selectedRowId;

    $("#pdfExport").click(function(){

           selectedRowId  = $("#'.$this->getViewPaneId().'input[name=\'rowSelectionRadio\']:checked").val();


       if(selectedRowId){    

            if(confirm("Are you sure to print this object ?")){
                printToPdf = true;
            }

        }else{
            printToPdf = false;
            alert("Please select an element from the table first.");
        }



            // create a temporarly form, in order to POST the data
            $("<form id=\"pdf-form\" method=\"post\" action=\"index.php?c=gridToPdf\"><input type=\"hidden\" name=\"gridObjId\" value=\"'.$this->viewPaneId.'\"></form>").appendTo("#rightcolumn");
            $("<input type=\"hidden\" name=\"headerText\" value=\"'.$headerText.'\">").appendTo("#pdf-form");
              $("<input type=\"hidden\" name=\"act\" value=\"exportObject\">").appendTo("#pdf-form");
              $("<input type=\"hidden\" name=\"rId\" value=\"'.selectedRowId.'\" >").appendTo("#pdf-form");


            // submit the form and remove it
            $("#pdf-form").submit().remove();
        }
    });';

rId 始终获取为值字符串“selectedRowId”,而不是 selectedRowId 变量的值。
有谁知道如何处理这个问题吗?

最佳答案

嗯,selectedRowId似乎没有定义,selectedRowId在php中也不是有效的变量,这就是为什么输入字段的值为selectedRowId 因为 php 认为它是一个字符串而不是一个变量。

/edit-> 好吧,我看到 selectedRowId 是一个 javascript 变量而不是 php 变量。因此,您需要使用“+”而不是“.”进行连接。和

关于javascript - 在输入 html 表单上从 java 脚本传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27876608/

相关文章:

javascript - 单击 jQuery 时读取 A 内的 IMG

javascript - 在第一次绘制之前修改 body 的类

php - "WHERE OR "在 Codeigniter PHP 的数据范围内加载数据

jquery - 我可以使用 jQuery 选择具有 XPath 属性模式的 DOM 节点吗?

jquery - 如何在不使用表单提交按钮的情况下发布使用 &lt;input type ="file"/> 上传的图片?

javascript - Android 横向/纵向视口(viewport)不同

javascript - 在 Angular 2 中处理来自 http.get 的成功和错误响应

php - 带有 "WHERE"问题的小型 php fetch 查询

php - 在 laravel 5.3 中按查询分组

DIY 移动 UI 层的 jQuery 与 jQuery Mobile 对比?