I have the following likert scale implemented in html (note the hidden field at the end):
<ul class="likert">
<li class="likert">Not Empathetic<input type="radio" value="1" />
<li class="likert"><input type="radio" value="2" />
<li class="likert"><input type="radio" value="3" />
<li class="likert"><input type="radio" value="4" />
<li class="likert">Very Empathetic<input type="radio" value="5" />
</ul>
<input class="answer-key" type="hidden" value="5"/>
I am trying to compare the value of the selected radio button with the value stored in the hidden field.
In jquery, I have the following:
$(document).ready(function(){
//click handler
$('input[type=radio]').click(function(){
var value = $(this).val();
//DOESN'T WORK
var answer = $(this).parent().siblings('.answer-key').val());
compute_score(answer,value);
});
});
How might I access the value of the hidden input? There will be multiple hidden answers on this page, so I need to get the value of the hidden answer for this particular likert scale. I am open to moving the hidden answer to another location (perhaps within the <ul>?).
.parentis not enough (that only selects the<li>). I think you want.closest('ul').siblings…