Reputation: 310
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?
Upvotes: 0
Views: 538
Reputation: 5025
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
Upvotes: 3