0

I have a problem with passing javascript variable as value on input hidden type on html form.

For more details :

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

Always rId gets as value string "selectedRowId", not the value of the selectedRowId var.
have any anyone any idea how to handle this problem?

1 Answer 1

3

well, selectedRowId doesn't seem to be defined and selectedRowId is also no valid variable in php, thats why the input field has the value selectedRowId as php thinks its a string rather than a variable.

/edit-> okey, I see that selectedRowId is a javascript variable and not a php variable. So you will need to to use "+" for concatination rather than "." and

2
  • Thanks for yours answer, I try with "+" but didn't work again. Commented Jan 10, 2015 at 13:44
  • 1
    I modify $("<input type=\"hidden\" name=\"rId\" value=\"'.selectedRowId.'\" >") as $("<input type=\"hidden\" name=\"rId\" id=\"rId\" value=\"\" >")...; and i have added document.getElementById("rId").value=+selectedRowId; this solved my problem :) Commented Jan 13, 2015 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.