0

I am trying to get the value of a selected radio button from my list form. There are three radio buttons. I noticed that when I get the value, I get a sharepoint generated value such as 'ct100', 'ct101' or 'ct102'. How do I know when a value is selected? When I look at the element in the debugger, I don't see the selected value with the 'selected' attribute. Any ideas? Below is what the debugger shows. As you can see, the value of the selected radio buttons shows 'ct100'. Also, how can I tell when a value is selected? The code below will return values that are not selected as well.

chrome debigger

2 Answers 2

2

Try this

document.querySelector("input[name^='Type_']:checked").value;

Output

enter image description here

2
  • 1
    Thank you! That worked but how did you get the returned value to match the actual value? The value returned is something like 'ct100', 'ct101', etc
    – JustMe
    Sep 12, 2018 at 18:49
  • You are welcome, In fact, the choice field radio button options are shown like inputs control, not like select control, and each option has an auto-generated name that contains the main name of a choice field, so you try to query the selector by the name that contains part of the choice field name or the full name if it doesn't have space! (based on the auto-generated name)! hope it clear and please don't hesitate to tell me if I didn't get your point :) Sep 12, 2018 at 19:45
0

We can use the following jQuery code to achieve it.

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function(){
    var selectedRadio=$("span.ms-standardheader:contains('Type Of Request')").closest("tr").find("input:checked").val();
    console.log(selectedRadio);
})
</script>
1
  • I only want to use vanilla JS. Thanks though!
    – JustMe
    Sep 12, 2018 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.