This piece of code below allows me to be able to set the text input to 1, if there are no answer buttons turned on from the chosen options of either "True or False" or "Yes or No".\[code\] var container = $btn.closest(".optionAndAnswer"); // here the zero gets assigned var answertxt = $(".answertxt", container); var numberison = $(".answerBtnsOn", container).length; var maxRowValue = http://stackoverflow.com/questions/13835028/$('.gridTxt', container).val();if (maxRowValue =http://stackoverflow.com/questions/13835028/=='True or False' || maxRowValue =http://stackoverflow.com/questions/13835028/=='Yes or No') { if (answertxt.val() == 1 && numberison == 0) { numberison = 1; }}\[/code\]Below is the relevant html the above code controls:\[code\]<form id="QandA" action="./QandATable2.php" method="post"> <table id="optionAndAnswer" class="optionAndAnswer"> <tr class="option"> <td>1. Option Type:</td> <td> <div class="box"> <input type="text" name="gridValues" class="gridTxt maxRow" id="mainGridTxt" readonly="readonly" /> <span href="http://stackoverflow.com/questions/13835028/#" class="showGrid" id="showGridId">[Open Grid]</span> </div> <table class="optionTypeTbl"> <tr> <td> <input class="gridBtns gridBtnsOff" name="btnTrueorFalseName" id="btnTrueorFalse" type="button" value="http://stackoverflow.com/questions/13835028/True or False" /> <input class="gridBtns gridBtnsOff" name="btnYesorNoName" id="btnYesorNo" type="button" value="http://stackoverflow.com/questions/13835028/Yes or No" /> </td> </tr> </table> </td> </tr> <tr class="numberAnswer"> <td>2. Number of Answers:</td> <td> <span class="na string" id="mainNa">Only 1 Answer</span> <input type="text" name="numberAnswer" class="numberAnswerTxt answertxt" id="mainNumberAnswerTxt" readonly="readonly" onChange="getButtons()"> </td> </tr> <tr class="answer"> <td>3. Answer</td> <td> <table id="answerSection"> <tr> <td> <input class="answerBtns answers answerBtnsOff" name="answerName[True]" id="answerTrue" type="button" value="http://stackoverflow.com/questions/13835028/True" onclick="javascript: btnclick(this, -1, true);" /> <input class="answerBtns answers answerBtnsOff" name="answerName[False]" id="answerFalse" type="button" value="http://stackoverflow.com/questions/13835028/False" onclick="javascript: btnclick(this, -1, true);" /> <input class="answerBtns answers answerBtnsOff" name="answerName[Yes]" id="answerYes" type="button" value="http://stackoverflow.com/questions/13835028/Yes" onclick="javascript: btnclick(this, -1, true);" /> <input class="answerBtns answers answerBtnsOff" name="answerName[No]" id="answerNo" type="button" value="http://stackoverflow.com/questions/13835028/No" onclick="javascript: btnclick(this, -1, true);" /> </td> </tr> </table> </td> </tr> </table></form>\[/code\]But my question is the how can I include this code in the function below? In the function below it appends the top control of the selected option, answers and number of answers from the top into an appended table row:\[code\]function insertQuestion(form) { var context = $('#optionAndAnswer'); var currenttotal = context.find('.answerBtnsOn').length; var $tbody = $('#qandatbl > tbody'); var $tr = $("<tr class='optionAndAnswer' align='center'>");var $td = $("<td class='extratd'>");var $noofanswers = $("<div class='noofanswers'>2. Number of Answers:<br/></div>");var $options = $("<div class='option'>1. Option Type:<br/></div>");var $answer = $("<div class='answer'>3. Answer:<br/></div>");var $questionType = ''; gQuestionIndex++; $('.gridTxt', context).each( function() { var $this = $(this); var $optionsText = $("<input type='text' class='gridTxtRow maxRow' readonly='readonly' />") .attr('name',$this.attr('name')+"[]") .attr('value',$this.val()) .appendTo( $options ) .after("<span href='http://stackoverflow.com/questions/13835028/#' class='showGrid'>[Open Grid]</span>"); $questionType = $this.val(); });$('.numberAnswerTxt', context).each(function() { var $this = $(this); var $noofanswersText = ''; if ($questionType == 'True or False' || $questionType == 'Yes or No'){ $noofanswersText = $("<span class='naRow string' style='display: block;'>Only 1 Answer</span><input type='text' class='numberAnswerTxtRow answertxt' style='display: none;' onkeyup='numberKeyUp(this)' onkeypress='return isNumberKey(event)' onChange='getButtons()'>").attr('name', $this.attr('name')+"[]").attr('value', $this.val()); }else{ $noofanswersText = $("<span class='naRow string' style='display: none;'>Only 1 Answer</span><input type='text' class='numberAnswerTxtRow answertxt' style='display: block;' onkeyup='numberKeyUp(this)' onkeypress='return isNumberKey(event)' onChange='getButtons()'>").attr('name', $this.attr('name')+"[]").attr('value', $this.val()); } $noofanswers.append($noofanswersText); }); var $this, i=0, $row, $cell;$('#optionAndAnswer .answers').each(function() { $this = $(this); if(i%7 == 0) { $row = $("<tr/>").appendTo($answer); $cell = $("<td/>").appendTo($row); } var $newBtn = $(("<input class='answerBtnsRow answers' type='button' style='display:%s;' onclick='btnclick(this, " + gQuestionIndex + ");' />").replace('%s', $this.is(':visible') ? 'inline-block' : 'none')).attr('name', "value[" + gQuestionIndex + "][]").attr('value', $this.val()).attr('class', $this.attr('class')).attr('id', $this.attr('id') + 'Row'); $newBtn.appendTo($cell); i++;}); $tr.append($td); $td.append($options); $td.append($noofanswers); $td.append($answer); $tbody.append($tr); }\[/code\]