I need to update from prompt 1 param in , but i get all the time a a JavaScript error "Cannot set property 'value'".
I need to set the "rejectReason" param to what the user has written in prompt and them to submit the action.
So Here's the code please help me to assign the variable to the param
<apex:form>
<apex:commandButton action="{!processRejectButton}" onclick="rejectCandidate();" oncomplete="return location.reload();" value="Reject Candidate" id="theCommandLink">
<apex:param name="approveId" assignTo="{!approveId}" value="{!c.con.ID}"/>
<apex:param name="rejectReason" assignTo="{!rejectReason}" value="text" id="rejectReason"/>
</apex:commandButton>
</apex:form>
<script>
function rejectCandidate(){
var missing = prompt("Enter reject reason details", "aaaa");
if (missing != null && missing != "") {
document.getElementById('{!$Component.rejectReason}').value = missing;
}else{
alert("Please enter missing info details");
}
}
</script>
Best Answer
You're half right here.
What you'll need to do is take the
<apex:param>
markup outside of the<apex:commandButton>
. The button should then only call a JavaScript method, passing in the Id of the Contact(?). It shouldn't have an action:Your
rejectCandidate()
method is fine as is, however it should do one more thing which is call a<apex:actionFunction>
that passes in the parameters to the controller.For example:
Alls we've really done to your JavaScript is add the latter part: something that calls
doRejectCandidate()
and passes in twoString
values (missing and contactId). "missing" is generated from the function you've already written, "contactId" is passed in from the button.Finally, you'll just need to have an
<apex:actionFunction>
with the namedoRejectCandidate
that then assigns the parameters and calls the action you initially set in your button.This will pass to the controller as a GET request, meaning you can then access the values of
missing
andcontactId
in yourprocessRejectButton()
method as below: