You need to sign in to do that
Don't have an account?
QuickDEV
passing the <apex:selectRadio> value to JavaScript Function
Hi,
I have <apex:selectRadio> tag in my VisualForce page with two radio buttons in it.
I need to pass the value of the selected radio button to a JavaScript function to carry out further functionality.
Here is what I am trying to do:
// partial code from Controller
public List<SelectOption> getStateCountry() {
List<SelectOption> nameCode= new List<SelectOption>();
nameCode.add(new SelectOption('state','state'));
nameCode.add(new SelectOption('Country','Country'));
return nameCode;
}
public String getNameCodeValue() {
return nameCodeValue;
}
public void setNameCodeValue(String nameCodeValue) { this.nameCodeValue = nameCodeValue; }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// partial code from VisualForce page
<script>
function testFunction(radval)
{
alert('in Testfunction : '+ radval);
}
</script>
<apex:form >
<apex:selectRadio id="nameCodeID" value="{!nameCodeValue}" onchange="testFunction('{!nameCodeValue}')" >
<apex:selectOptions value="{!nameCode}"/>
</apex:selectRadio>
</apex:form >
============
Alert says: "in Testfunction : undefined"
Am I going in the right direction, please help.
Thanks
I have <apex:selectRadio> tag in my VisualForce page with two radio buttons in it.
I need to pass the value of the selected radio button to a JavaScript function to carry out further functionality.
Here is what I am trying to do:
// partial code from Controller
public List<SelectOption> getStateCountry() {
List<SelectOption> nameCode= new List<SelectOption>();
nameCode.add(new SelectOption('state','state'));
nameCode.add(new SelectOption('Country','Country'));
return nameCode;
}
public String getNameCodeValue() {
return nameCodeValue;
}
public void setNameCodeValue(String nameCodeValue) { this.nameCodeValue = nameCodeValue; }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// partial code from VisualForce page
<script>
function testFunction(radval)
{
alert('in Testfunction : '+ radval);
}
</script>
<apex:form >
<apex:selectRadio id="nameCodeID" value="{!nameCodeValue}" onchange="testFunction('{!nameCodeValue}')" >
<apex:selectOptions value="{!nameCode}"/>
</apex:selectRadio>
</apex:form >
============
Alert says: "in Testfunction : undefined"
Am I going in the right direction, please help.
Thanks
<script> function testFunction(therad) { alert('in Testfunction : ' + therad.value); } </script> <apex:form > <apex:selectRadio id="nameCodeID" value="{!nameCodeValue}" onchange="testFunction(this)" > <apex:selectOptions value="{!nameCode}"/> </apex:selectRadio> </apex:form >
All Answers
I Apologize for the errors in above code.
Correct version:
// partial code from Controller
public List<SelectOption> getnameCode() {
List<SelectOption> nameCode= new List<SelectOption>();
nameCode.add(new SelectOption('name','name'));
nameCode.add(new SelectOption('code','code'));
return nameCode;
}
public String getNameCodeValue() {
return nameCodeValue;
}
public void setNameCodeValue(String nameCodeValue) { this.nameCodeValue = nameCodeValue; }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// partial code from VisualForce page
<script>
function testFunction(radval)
{
alert('in Testfunction : '+ radval);
}
</script>
<apex:form >
<apex:outputLabel value="Search By:"/>
<apex:selectRadio id="nameCodeID" value="{!nameCodeValue}" onchange="testFunction('{!nameCodeValue}')" >
<apex:selectOptions value="{!nameCode}"/>
</apex:selectRadio>
</apex:form >
Help please....tried all ways I could
<script> function testFunction(therad) { alert('in Testfunction : ' + therad.value); } </script> <apex:form > <apex:selectRadio id="nameCodeID" value="{!nameCodeValue}" onchange="testFunction(this)" > <apex:selectOptions value="{!nameCode}"/> </apex:selectRadio> </apex:form >
is there anyway to get the value of selected radio button value without using 'this' keyword.
in jquery can we get the value using Id = 'nameCodeID' ?