You need to sign in to do that
Don't have an account?

jquery selector for radio button
I have a form with a radio button and based on the selection of the button I would like to toggle divs. The id of the radio buttons are ending with :0 and :1, so I cannot use partial selector. What is the work around for this and what is the best way in general? I am a jquery user but very new to SF. Thanks.
<script type="text/javascript">
var j$ = jQuery.noConflict();
j$(document).ready(function(){
j$('input[id$=contactMethod:0]').change(function(){
//do something
});
});
</script>
<apex:form>
<apex:selectRadio layout="pageDirection" id="contactMethod" >
<apex:selectOption itemLabel="Address" itemValue="a"/>
<apex:selectOption itemLabel="Phone Number" itemValue="f"/>
</apex:selectRadio>
<div id="phone">
Phone: <input type="text"/>
</div>
<div id="address">
Address: <input type="text"/>
</div>
</apex:form>
<script type="text/javascript">
var j$ = jQuery.noConflict();
j$(document).ready(function(){
j$('input[id$=contactMethod:0]').change(function(){
//do something
});
});
</script>
<apex:form>
<apex:selectRadio layout="pageDirection" id="contactMethod" >
<apex:selectOption itemLabel="Address" itemValue="a"/>
<apex:selectOption itemLabel="Phone Number" itemValue="f"/>
</apex:selectRadio>
<div id="phone">
Phone: <input type="text"/>
</div>
<div id="address">
Address: <input type="text"/>
</div>
</apex:form>
A small code for your scenario.
Thanks,
pRAMODH.
All Answers
The selector you are using should work if you format it this way: j$("input[id$='contactMethod\\:0']") You probably just need to escape the : with the \\
A small code for your scenario.
Thanks,
pRAMODH.