Reputation: 16629
Hi I have the following html code
<td>
Question1
<input type="radio" value="1" name="1" id="1_1">Agree
<input type="radio" value="2" name="1" id="1_2">Dis-Agree
<input type="text" size="30" name="1[answer]" id="1_answer" class="answer">
</td>
<td>
Question2
<input type="radio" value="1" name="2" id="2_1">Agree
<input type="radio" value="2" name="2" id="2_2">Dis-Agree
<input type="text" size="30" name="2[answer]" id="2_answer" class="answer">
</td>
<input type="text" size="30" name="feedback[answers]" id="feedback_answers">
What I want to do is
I was manage to the first steps, but I cannot get the values from Ex: 1_answer text box to 'feedback_answers' text box, following is my JQuery code
$(document).ready(function() {
$("input:radio[type=radio]").click(function() {
id = $(this).attr('id');
ids = id.split("_")
question_id = ids[0]
answer_id = ids[1]
$('#' + question_id + '_answer').val(answer_id);
$(".answer").each(function(index, value){
alert(this.val)
});
});
can someone help me, I want to loop through all the 'asnwer' text boxes (Ex: 1_answer) and get all of them to 'feedback_answers' text box.
thanks in advance
Upvotes: 0
Views: 44
Reputation: 9869
Try This
$(document).ready(function() {
var feedback_answers = $("#feedback_answers");
$("input[type=radio]").click(function() {
var id = $(this).attr('id');
var ids = id.split("_")
var question_id = ids[0]
var answer_id = ids[1];
var answers = [];
$('#' + question_id + '_answer').val(answer_id);
$(".answer").each(function(index, value){
//alert($(this).val())
answers.push($(this).val());
});
feedback_answers.val(answers.join());
});
Upvotes: 1