You need to sign in to do that
Don't have an account?
how to pass a radio button value to javascript
Hi,
The following is my code...which has a problem.
<apex:page>
<apex:form id="theForm">
<apex:selectRadio id="theRadio" onchange="test()">
<apex:selectOption itemValue="india" itemLabel="India" />
<apex:selectOption itemValue="ap" itemLabel="AP" />
</apex:selectRadio>
<script>
function test()
{
alert('you selected :'+'document.getElementById('{!$component.theForm.theRadio}').value);
}
</script>
</apex:form>
</apex:page>
my doubt is why it was not trigger means the alert is not working..................
please can any one tell me the reason and solution also.
Thanks
Srikanth
Okay, got everything to work now. You need to iterate over all the elements in the radio button set to figure out which one is checked :-
Try it out. If it works, please mark it as answer.
All Answers
Why are you trying through Javascript you may use action function for ajax call and Pass back to the controller and perform action in page refrence ?
thanks for ur reply........i already used actionFunction ,i got it but i want the solution of above requirement.......
And in your controller or extension, have a property :-
Whatever value is selected in the radiobutton will be available in your property.
Hi Saurabh ,
the value of radio button will available to the property of controller...but it was not triggerd.......
please help me on my query......
Put the script block before the radio button :-
I do see that the selectedValue shows as "undefined", definitely a way in javascript to figure that out.
Okay, got everything to work now. You need to iterate over all the elements in the radio button set to figure out which one is checked :-
Try it out. If it works, please mark it as answer.
thank you saurabh..it worked