I assume that the "two separate hidden short text boxes" are in a multiple-text question.
Lets call the multiple-options-with-comments question Q1 and the multiple-text question Q2
If Q1 and Q2 are on the same page, you can do this:
1)
Set up your survey to use JavaScript
.
2) Add the following script to the source of one of the questions. Replace "11" with the Q1
question ID
and "22" with the Q2
question ID
.
The script does the following:
- Hides the first two text inputs in Q1
- Makes the visible comments mandatory if their associated box is checked
- Loads the text of the first two checked options in Q1 into the text inputs of Q2 (if the option has a visible comment, that is loaded instead)
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var q1ID = 11;
var q2ID = 22;
var msg = 'Please specify in the comment box.';
// Hide the first 2 text inputs of Q1
$('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide();
$('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide();
// Interrupt next/submit function
$('#movenextbtn, #movesubmitbtn').click(function(){
// Reset some stuff
var failedMandatory = 0;
$('#question'+q1ID+' input.text').css({'background':''});
$('#question'+q2ID+' input.text').val('');
// Loop through all check answers in Q1
$('#question'+q1ID+' input.checkbox:checked').each(function(i){
// Define the row
var thisRow = $(this).parents('li:eq(0)');
// Check for empty mandatory text inputs
if($('input.text:visible', thisRow).length > 0 && $('input.text', thisRow).val() == '') {
$('input.text', thisRow).css({'background':'pink'});
failedMandatory = 1;
}
// Load the multiple-text question
if($('input.text:visible', thisRow).length > 0) {
$('#question'+q2ID+' input.text:eq('+i+')').val($('input.text', thisRow).val());
}
else {
$('#question'+q2ID+' input.text:eq('+i+')').val($.trim($(this).parent().text()));
}
});
// Abort submit if any mandatory text inputs are empty
if(failedMandatory == 1) {
alert (msg);
return false;
}
else {
return true;
}
});
});
</script>