Trouble with inserting text from a few form field into the HTMLArea at the same time in the same page

Trouble with inserting text from a few form field into the HTMLArea at the same time in the same page

написао/ла Maria B. -
Број одговора: 0
Hallo,
Since we are using a lot of "cloze" questions in our quizzes, a friend of mine helpped me to make costume template for it. We added some hidden, checkbox and text form fields in close question page, just below HTLM area and tried to add text from these fields with a button.

JavaScript code:
<script language="JavaScript" type="text/javascript">
/*by Br@nkoR*/
function init() {
  var form = document.theform;
  var parametri = getData(1);
  var vrednosti = getDataVal(2);
  var znacajnosti = getData(3);
  form.questiontext.value += "\n" + parametri + "\n\n" + vrednosti + "\n\n" + znacajnosti;
  return true;
}
function getData(index) {
  var form = document.theform;
  var txt = form.elements['tekst_'+index].value;
  var prefix = form.elements['prefix_'+index].value;
  var sufix = form.elements['sufix_'+index].value;
  var txtBoxs = form.elements['txt_'+index+'[]'];
  var checkBoxs = form.elements['chb_'+index+'[]'];
  var setAnswers = new Array();
  for(var i=0, len = txtBoxs.length; i<len; i++) {
    if(txtBoxs[i].value.length) {
      setAnswers[i] = (checkBoxs[i].checked) ? ('=' + txtBoxs[i].value) : txtBoxs[i].value;
    }
  }
  var output = setAnswers.join('~');
  return txt + ' ' + prefix  + output + sufix;
}
function getDataVal(index) {
  var form = document.theform;
  var txt = form.elements['tekst_'+index].value;
  var prefix = form.elements['prefix_'+index].value;
  var sufix = form.elements['sufix_'+index].value;
  var infix = form.elements['infix'].value;
  var txtBoxs = form.elements['txt_'+index+'[]'];
  var setAnswers = new Array();
  for(var i=0, len = txtBoxs.length; i<len; i++) {
    if(txtBoxs[i].value.length) {
      setAnswers[i] = txtBoxs[i].value;
    }
  }
  var output = setAnswers.join(infix);
  return txt + ' ' + prefix  + '=' + output + sufix;
}

function selectChbox(elem) {
  var elemName = elem.name;
  var elemItems = document.theform.elements[elemName];
  for(var i = 0; i < elemItems.length; i++) {
    elemItems[i].checked = false;
  }
  elem.checked = true;

</script>

-----------------------------------------------
<input name="add" value="Add Data to HTMLArea" type="button" onClick="init()" />

For some reason, it is not possible.
I had to replace this:

          <?php  if (isset($err["questiontext"])) {
               formerr($err["questiontext"]);
               echo "<br />";
           }
           print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);
           if ($usehtmleditor) {
               helpbutton("richtext", get_string("helprichtext"), "moodle");
           } else {
               helpbutton("text", get_string("helptext"), "moodle");
           }
        ?>

with this regular textarea box:

<textarea id="edit-questiontext" name="questiontext" rows="15" cols="65"></textarea>

so that can work.

There is no i-frame or something like that in html code for this page.

What should I do? I want to keep HTMLArea.

<script language="javascript" type="text/javascript" defer="defer">
edit_questiontext = new HTMLArea('edit-questiontext');
var config = edit_questiontext.config;
config.pageStyle = "body { background-color: #ffffff; font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; }";
config.killWordOnPaste = true;
config.fontname = {
"Trebuchet":	'Trebuchet MS,Verdana,Arial,Helvetica,sans-serif',
"Arial":	'arial,helvetica,sans-serif',
"Courier New":	'courier new,courier,monospace',
"Georgia":	'georgia,times new roman,times,serif',
"Tahoma":	'tahoma,arial,helvetica,sans-serif',
"Times New Roman":	'times new roman,times,serif',
"Verdana":	'verdana,arial,helvetica,sans-serif',
"Impact":	'impact',
"Wingdings":	'wingdings'};
edit_questiontext.generate();
</script>