document.form的Javascript问题

document.form的Javascript问题,javascript,Javascript,我正在尝试运行代码,但我不知道是什么导致了问题。它以前是有效的,现在我试着这样做: function makeUnderline(formName,editor) { var txt = window.prompt("Enter the text you wish to be underlined.", "Enter Text Here"); if (txt != null) { document.formName.editor.value += "<u&g

我正在尝试运行代码,但我不知道是什么导致了问题。它以前是有效的,现在我试着这样做:

function makeUnderline(formName,editor) {
    var txt = window.prompt("Enter the text you wish to be underlined.", "Enter Text Here");
    if (txt != null) {
        document.formName.editor.value += "<u>" + txt + "</u>";
    }
    document.formName.editor.focus();
}

<input type="button" name="bUnderline" value=" underline " onClick="makeUnderline('formFaqs','answer');" alt="Use this button to create text that is underlined." title="Use 
this button to create text that is underlined.">
函数makeUnderline(formName,编辑器){
var txt=window.prompt(“输入要加下划线的文本。”,“在此处输入文本”);
如果(txt!=null){
document.formName.editor.value+=“”+txt+“”;
}
document.formName.editor.focus();
}
我得到一个错误:

TypeError: document.formName is undefined

document.formName.editor.value += "<u>" + txt + "</u>";
TypeError:document.formName未定义
document.formName.editor.value+=“”+txt+“”;

如果要将表单名称作为变量传递,则需要使用括号表示法

document.forms[formName].elements[editor].value += "<u>" + txt + "</u>";
document.forms[formName].elements[editor].value+=“”+txt+“”;

页面顶部包含javascript您是指document.forms[formName]而不是document.formName表单的实际名称是什么?非常酷。谢谢你,伙计。这解决了我的问题,至少我在这里也学到了新东西。干杯