我正在尝试用 java 脚本中的字符串填充某个文本区域。我已经在我的函数中将字符串定义为变量“result”,并让函数返回变量结果。当它返回“结果”时,我希望它在特定的文本区域中返回。所以我使用 document.getElementByID 调用了文本区域,但它不会填充文本区域。我不确定我在哪里出错或从这里去哪里。任何帮助将不胜感激。我在下面包含了表单和函数的代码。
JavaScript
function newVerse(form1) {
var objects = form1.objects.value;
var destination = form1.destination.value;
var result = "Where have all the" + objects + "gone?" + "Long time passing." + "Where have all the" + objects + "gone?" + "Long time ago." + "Where have all the" + objects + "gone?" + "Gone to" + destination + ", everyone." + "When will they ever learn?" + "When will they ever learn?";
document.getElementByID(textarea).value += result
return result;
}
HTML
<form name=form1>Objects:
<input type="text" name="objects">
<br>Destination:
<input type="text" name="destination">
<br>
<input type="button" name="submit" value="Submit" onclick="newVerse(form1)">
</form>