jQuery > Get radio button value
by KelseyW
HTML
<div id="YSR_Page:DS_YSR_Mock:mainBlock" class="bPageBlock brandSecondaryBrd apexDefaultPageBlock secondaryPalette">
<div class="pbHeader">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<div class="pbBody">
<span id="YSR_Page:DS_YSR_Mock:mainBlock:j_id27"></span>
<div class="striped-question" id="questionRows">
<div class="form-group">
<label class="col-md-12 col-lg-5 control-label" id="questionLabel">
<span class="nmbr">1.</span>Acts too young for his/her age
</label>
<div class="col-md-12 col-lg-7" id="fieldset1">
<span class="nmbr"></span>
<fieldset style="border: none;">
<table role="presentation" id="YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections" class="radio-list radio-list-inline">
<tbody>
<tr>
<td>
<input name="YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections" id="YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections:0" value="0" type="radio">
<label for="YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections:0">
0 = Not True
</label>
</td>
<td>
<input name="YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections" id="YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections:1" value="1" type="radio">
<label for="YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections:1">
1 = Somewhat or Sometimes True
</label>
</td>
<td>
<input name="YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections"...
CSS
.focused {
outline: 1px solid red;
}
JavaScript
$(function() {
/*focus*/
/* $document.ready(function getQ() {
var theQ = document.getElementsByName('{!$Component.DS_YSR_Mock.mainBlock.qContent}');
for (var i = 0; i < qContent.length; i++){
theQ.focus();
}
alert(theQ+' is focused');
})*/
$(':input').keyup(function(e) {
$(this).closest('table').next().find('.radio-list-inline').first().focus();
})
/*
inputs = $("table :input");
$(inputs).keypress(function(e){
if (e.keyCode == 13){
inputs[inputs.index(this)+1].focus();
}
});
*/
document.addEventListener('keydown', (event) => {
const keyName = event.key;
if (keyName === '0' || keyName === '1' || keyName === '2') {
var activeEle = $(document.activeElement).attr('name');
alert('You pressed ' + keyName + '. ' + activeEle + ' is active.');
/*click q1=1, key 0 -> "You pressed 0. YSR_Page:DS_YSR:mainBlock:qContent:0:radioSelections is active."*/
/* $("input[name='" + name + "][value='" + keyName + "']").prop('checked', true);*/
}
})
$('input[type=radio]').change(function() {
var value = $(this).filter(':checked').val();
/*var getName = $(this).attr('name');*/
/*var selection=$(this).val();*/
/*YSR_Page:DS_YSR:mainBlock:qContent:*/
var qNum = (parseInt($(this).attr('name').substring(40, 41)) + 1) || 1;
alert('Question ' + qNum + ' = ' + value);
});
});
/*
$(function(){
document.addEventListener('keydown', (event) =>
{ const keyName = event.key;
alert('You pressed '+ keyName)})
$(window).keyup(function(e){
var keyPressed = (e.keyCode?e.keyCode : e.which);
if(keyPressed == 9 ){
$("#[name*='fieldset']:focus");
alert('tab was fired');
}};
$("#get").click(function(){
var myradios = document.querySelector('radio-list');
var qName =$("input[name*='radioSelections']");
$("#debug").html("Name is"+qName);
});
});
*/
/*
$function...