You need to sign in to do that
Don't have an account?
John Neilan 2
Visualforce Radio Button Value to Object
Hello,
I have a VF page on the Account. I have set up 3 radio selections using apex:selectRadio and a Script. I would now like to populate a custom field (Type__c) with the radio selection the user chose. Does anyone know how I can do this? Thanks,
I have a VF page on the Account. I have set up 3 radio selections using apex:selectRadio and a Script. I would now like to populate a custom field (Type__c) with the radio selection the user chose. Does anyone know how I can do this? Thanks,
<apex:page standardController="Account" tabStyle="Account"> <script> function TypeSelect(variable) { var choice = variable.value; if(choice == 'Amp'){ document.getElementById('layoutAmp').style.display = 'block'; document.getElementById('layoutEng').style.display = 'none'; document.getElementById('layoutAge').style.display = 'none'; } else if(choice == 'Eng'){ document.getElementById('layoutAmp').style.display = 'none'; document.getElementById('layoutEng').style.display = 'block'; document.getElementById('layoutAge').style.display = 'none'; } else{ document.getElementById('layoutAmp').style.display = 'none'; document.getElementById('layoutEng').style.display = 'none'; document.getElementById('layoutAge').style.display = 'block'; } } </script> <style> input[type=radio] {margin-left: 100px;} .radioClass {margin-left: 25%;} </style> <apex:form > <apex:actionRegion > <Table width="90%" border="0" cellpadding="0" cellspacing="0" columns="5"> <tr> <td colspan="5" class="fieldLabel"> <apex:selectRadio layout="lineDirection" styleClass="radioClass" onclick="TypeSelect(this);"> <apex:selectOption itemLabel="Amplify" itemValue="Amplify"></apex:selectOption> <apex:selectOption itemLabel="Engage" itemValue="Engage"></apex:selectOption> <apex:selectOption itemLabel="Agency" itemValue="Agency"></apex:selectOption> </apex:selectRadio> <apex:actionSupport event="onchange" reRender="Detail"/> </td> </tr> </Table>
If you're doing this all client side, it's a bit more tricky. You'll want to create a hidden input field, and then set that via javascript. I've taken a shot at it below. Keep in mind that you'll likely have to play around with $Component.Type__c to return the correct id.
<apex:selectRadio layout="lineDirection" styleClass="radioClass"onclick="TypeSelect(this);">
To this:
<apex:selectRadio value="{!Type__c}" layout="lineDirection" styleClass="radioClass"onclick="TypeSelect(this);">
Type__c must be a field on Account object.
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
Thanks. I actually misspoke, there are 3 checkbox fields I want to update depending upon the values selected in the selectRadio.
@James,
I tried inserting: but nothing populated when I saved the record. Do I have the format correct?
If you post what you have so far, that would help.