Okay, using the "No Answer" survey setting simplifies things a bit and to expand a little on your line of thinking...
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify the questions
var thisQuestion = $('#question'+{QID}+'');
var nextQuestion = $(thisQuestion).nextAll('.text-short:eq(0)');
// Hide the short-text question
$(nextQuestion).hide();
// Move the hidden text input into the array
$('th.answertext:last', thisQuestion).append($('input[type="text"]', nextQuestion)).closest('tr').addClass('otherRow');
// Some styling...
$('input[type="text"]', thisQuestion).css({
'width': '50%'
});
// Handle the "Other" radios
$('input[type="text"]', thisQuestion).on('keyup change',function(event){
event.stopPropagation();
if($.trim($(this).val()) == '') {
$('.otherRow input:radio[value!=""]', thisQuestion).prop('checked',false);
$('.otherRow input:radio[value=""]', thisQuestion).click();
}
else {
$('.otherRow input:radio[value=""]', thisQuestion).prop('checked',false);
}
});
// Handle the "Other" text input
$('.otherRow input.radio', thisQuestion).on('click',function(event){
if($(this).attr('value') == '') {
$('.otherRow input[type="text"]', thisQuestion).val('');
}
});
// Validate the "Other" text input(s) on submit
if($('#movenextbtn, #movesubmitbtn').attr('data-inserted-other') != 'true') { // We're only doing this once on this page
$('#movenextbtn, #movesubmitbtn').attr('data-inserted-other', 'true').on('click.insertedOther', function (event) {
var otherError = 0;
$('.array-flexible-row .otherRow').each(function(i) {
if(($('input:radio[value!=""]:checked', this).length > 0 && $('input[type="text"]', this).val() == '') || ($('input:radio[value!=""]:checked', this).length == 0 && $('input[type="text"]', this).val() != '')) {
otherError = 1;
}
});
if(otherError == 1) {
alert('Please review your answer in the "Other" row(s).');
return false;
}
});
}
});
</script>