javascript - Post answer in comments on check of radio button -


i want make code in way once check right radio button(yes/no) along question shows in textarea. if yes radio button checked.. want yes show in textarea right question question 1, if no radio button checked, want no show in textarea. here have right now:

html:

question 1 yes<input id='chk1' value="yes" type='radio' />no<input name='chk3' value="no" type='checkbox' /><br /> question 2 yes<input id='chk2' value="yes" type='radio' />no<input name='chk3' value="no" type='checkbox' /><br /> question 3 yes<input id='chk3' value="yes" type='radio' />no<input name='chk3' value="no" type='checkbox' /><br /> other comments<textarea id='comment'></textarea><br /><input type=submit name=submit value='post' /> 

jquery:

$('#chk1').change(function(){     $('#comment').text("question 1:" + ""); }); $('#chk2').change(function(){     $('#comment').text("question 1:" + ""); }); $('#chk3').change(function(){     $('#comment').text("question 1:" + ""); }); 

jsfiddle:

http://jsfiddle.net/gk05pkkh/3/

you should using "name" not "id" on inputs can shared.

html:

question 1 yes<input name='chk1' value="yes" type='radio' />no<input name='chk1' value="no" type='radio' /><br /> question 2 yes<input name='chk2' value="yes" type='radio' />no<input name='chk2' value="no" type='radio' /><br /> question 3 yes<input name='chk3' value="yes" type='radio' />no<input name='chk3' value="no" type='radio' /><br /> other comments<textarea id='comment'></textarea><br /><input type=submit name=submit value='post' /> 

jquery:

$('input[name="chk1"]').change(function(){     checkquestion("question 1", this.value); }); $('input[name="chk2"]').change(function(){     checkquestion("question 2", this.value); }); $('input[name="chk3"]').change(function(){     checkquestion("question 3", this.value); });  function checkquestion(text, value) {     if ($('#comment').text().indexof(text)<0)         $('#comment').text($('#comment').text() + text + ":" + value + "\n");     else {         var oldvalue = 'yes';         if (value==='yes') oldvalue = 'no';         $('#comment').text($('#comment').text().replace(text + ":" + oldvalue, text + ":" + value));     } } 

http://jsfiddle.net/gk05pkkh/24/


Comments

Popular posts from this blog

php - How to modify a menu to show sub-menus -

shopping cart - Page redirect not working PHP -

python - Installing PyDev in eclipse is failed -