I'm trying to pass a variable from a javascript inside a VF page to a varibale in the Apex Controller.
The VF page code is:
<apex:page controller="uploadDataTosObject" apiVersion="36.0">
[Code....]
<apex:form>
<script>
function setVal(result)
{
document.getElementById("{!$Component.hdnField}").value =result;
}
</script>
<apex:inputHidden id="hdnField" value="{!myblob}" />
<apex:commandButton value="Post Page" action="{!post}" />
</apex:form>
<script>
setVal();
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script>
[Code...]
function to_csv(workbook) {
var result = [];
workbook.SheetNames.forEach(function(sheetName) {
var csv = X.utils.sheet_to_csv(workbook.Sheets[sheetName]);
if(csv.length > 0){
result.push("SHEET: " + sheetName);
result.push("");
result.push(csv);
}
});
output = setval(result.join("\n"));
return result.join("\n");
}
[Code...]
</body>
</apex:page>
this is the VF controller:
public with sharing class uploadDataTosObject {
public String myblob {get; set;}
public void post(){
system.debug(myblob);
}
}
I need to assaign "result.join("\n")" to the variable "myblob" inside the controller. Now I'm trying to use an "apex:inputhidden", but the System.debug shows "undefined" in the Logs. How can I assign the variable "result.join()" to "myblol"?
public void setContent(String value) { myBlob = Blob.valueOf(value); }
. Then bind yourinputHidden
tocontent
.