2015-01-10 17 views
0

我在將javascript變量作爲輸入隱藏類型的值傳遞給html表單時遇到了問題。在輸入html表單上傳遞來自java腳本的參數

有關詳細信息:

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(); 
     } 
    });'; 

始終擺脫得到的字符串值 「selectedRowId」,該selectedRowId VAR的不是值。
有任何人有任何想法如何處理這個問題?

回答

3

好,selectedRowId似乎並沒有被定義和selectedRowId也是PHP中沒有有效的變量,這就是爲什麼輸入字段作爲PHP認爲它是一個字符串,而不是一個變量的值selectedRowId

/edit-> okey,我看到selectedRowId是一個JavaScript變量,而不是一個PHP變量。所以你需要使用「+」進行連接而不是「」。「和

+0

謝謝你的回答,我嘗試用「+」但沒有再次工作。 – Saimir

+1

我修改$(「」)as $(「「)...;我已經添加了document.getElementById(「rId」)。value = + selectedRowId;這解決了我的問題:) – Saimir