That's what I thought, but I guess I don't understand the action function component or ajax that well.
Here is what I am working on. I have a VisualForce Page that has two radio buttons, PDF and Email (Used input type="radio") and a command button called Submit.
What I have now is once the user selects the PDF radio and click Submit, I have a javascript function that will open a new window and generate the customized PDF. As far as the Email option, I have a Page Reference method inside the apex controller extension that will attach the pdf to an e-mail and send it to a specific user.
What I would like is in that same Javascript function that opens the new window to also call the PageReference method depending on which radio button was selected. Could you give me an example on how either the action function or ajax could accomplish that? Please let me know if you need more information.
Here is how you call the action functionI guess you know where to add these. When you click the command button it would call the javascript function where yoyu can decide what to call , whether to render the pdf or the apex method. If it is apex method call the apex function as shown above and give the reference of your apex method in the actionfunction. That would solve the problem Thanks, Sandeep peddireddy
if ($("input[@radioOption]:checked").val() == "Email")
{
submitAction;
}
else if ($("input[@radioOption]:checked").val() == "Print")
{
window.open("{!PDF_URL}");
}
}
Hopefully it was formatted here correctly. When I select Email and hit submit nothing happens. I think I'm missing something in the apex command button but I'm not sure what exactly. Does the action function need apex:param as well?
Dude you are not calling the correct javascript function. And properly define the javascript function. See the below example how I have called the functionThansks, Sandeep Peddireddy
Sorry, I'm not sure I understand. Do you mean the function is misssing the script tags? The tags are there in the code (<script type="text/javascript"> </script> and the function is at the top of the visual force page (also included <apex:includeScriptvalue="{!$Resource.jquery}"/>). I should probably post the entire code.
yes, you can do that by using the action:function component or by making an ajax call making your pagereference method as a webservice.
That's what I thought, but I guess I don't understand the action function component or ajax that well.
Here is what I am working on. I have a VisualForce Page that has two radio buttons, PDF and Email (Used input type="radio") and a command button called Submit.
What I have now is once the user selects the PDF radio and click Submit, I have a javascript function that will open a new window and generate the customized PDF. As far as the Email option, I have a Page Reference method inside the apex controller extension that will attach the pdf to an e-mail and send it to a specific user.
What I would like is in that same Javascript function that opens the new window to also call the PageReference method depending on which radio button was selected. Could you give me an example on how either the action function or ajax could accomplish that? Please let me know if you need more information.
I think you were trying to show me how to enter the action function but I don't see it on your post.
Anyway, to help out here is the action function I have on the Visual Force Page:
<apex:actionFunctionname="submitAction"action="{!submitAction}"rerender=""/>
Here are the radio inputs and the apex command submit button:
<divstyle="text-align: center">
PDF:
<inputtype="radio" value="Print" name="radioOption" id="radioOption" onclick="togglePrintEmailState();"/>
Email:
<inputtype="radio" value="Email" name="radioOption" id="radioOption" onclick="togglePrintEmailState();"/>
</div>
<apex:commandButton value="Submit" onclick="open_or_email();"/>
And here is the Javascript function:
functionopen_or_email()
{
if ($("input[@radioOption]:checked").val() == "Email")
{
submitAction;
}
else if ($("input[@radioOption]:checked").val() == "Print")
{
window.open("{!PDF_URL}");
}
}
Hopefully it was formatted here correctly. When I select Email and hit submit nothing happens. I think I'm missing something in the apex command button but I'm not sure what exactly. Does the action function need apex:param as well?
Sorry, I'm not sure I understand. Do you mean the function is misssing the script tags? The tags are there in the code (<script type="text/javascript"> </script> and the function is at the top of the visual force page (also included <apex:includeScriptvalue="{!$Resource.jquery}"/>). I should probably post the entire code.
Also I can't see the example on your post.