我正在尝试根据我的需要修改 PVCS(版本管理器)网络版本。该产品是用 JSP 编写的。我的问题是当我添加一个简单的组合框时,我收到以下错误,我不知道为什么?!我调试了代码,但我再也找不到问题了,请帮助我解决问题。
对话框.jsp
Line: 281
Error: 'elements[...].value' is null or not an object
我收到错误的函数:请查找:alert(name + " -a- "+ targetForm.elements[name].value)
/* copy form data from one form to another */
function copyFormData(targetForm, sourceForm)
{
for (var i = 0; i < sourceForm.elements.length; i++) {
element = sourceForm.elements[i]
type = sourceForm.elements[i].type
if (type == "text" || type == "textarea" || type == "password") {
name = sourceForm.elements[i].name
zField = eval("targetForm['"+ name+"']");
if ( validElement( zField ) )
targetForm.elements[name].value = sourceForm.elements[i].value
}
else if (type == "checkbox") {
name = sourceForm.elements[i].name
if (sourceForm.elements[i].checked)
targetForm.elements[name].value = sourceForm.elements[i].value
}
else if (type == "radio") {
name = sourceForm.elements[i].name
if (sourceForm.elements[i].checked)
targetForm.elements[name].value = sourceForm.elements[i].value
}
else if (type == "select-one") {
name = sourceForm.elements[i].name
selectedIndex = sourceForm.elements[i].selectedIndex
alert(name + " -a- "+ targetForm.elements[name].value)
if (sourceForm.elements[i].options[selectedIndex].value != "")
targetForm.elements[name].value = sourceForm.elements[i].options[selectedIndex].value
else
targetForm.elements[name].value = sourceForm.elements[i].options[selectedIndex].text
}
else if (type == "select-multiple") {
// FIXME_CWP - this code only handles the first selection from
// a selection of type select-multiple. Currently, there are
// no cases where this is used. Before multiple selections
// are properly handled, a suitable delimiter must be decided
// upon.
// The main reason this was done was because Netscape interprets
// a select box of size > 1 as a select-multiple
name = sourceForm.elements[i].name
selection = sourceForm.elements[i].options;
selectedIndex = -1;
for (var j = 0; j < selection.length; j++) {
if (selection[j].selected) {
selectedIndex = j;
break;
}
}
if (sourceForm.elements[i].options[selectedIndex].value != "")
targetForm.elements[name].value = sourceForm.elements[i].options[selectedIndex].value
else
targetForm.elements[name].value = sourceForm.elements[i].options[selectedIndex].text
//alert("selectedIndex: " + selectedIndex + "\n" + targetForm.elements[name].value);
}
}
}
CCheckout.jsp -> 在这个文件的下面一行:
copyFormData(masterForm, tabForm);
masterForm 为空,这就是我收到错误消息的原因,但为什么呢?由于没有我的组合框页面工作正常。
/* submit master form using elements from other forms */
function onSubmit(masterForm)
{
// Get the check out location value.
/*
if (isNetscape)
masterForm.<%=options.WORKING_FOLDER%>.value = document.general_layer.document.applets[0].getEditFieldContents();
else
masterForm.<%=options.WORKING_FOLDER%>.value = document.applets[0].getEditFieldContents();
*/
//alert('Check out location=' + masterForm.<%=options.WORKING_FOLDER%>);
// Copy the fields from the General form
tabForm = getForm("general_form", "general_layer")
<%-- START Added by Vamsi on 21st May 2003
This is done as part of the Vm_secondary_performance_functional_spec
--%>
if(tabForm.<%=options.CHECKOUT_BY_DATE_RADIO_CHOICE%>.checked)
{
advTabForm = getForm("advanced_form", "advanced_layer");
advTabForm.<%=options.CHECKOUT_BY_DATE%>.checked = 1;
}
<%-- END Added by Vamsi on 21st May 2003 --%>
copyFormData(masterForm, tabForm);
// Get the workfile options index from the general form and set
// as correct value in the master form. Note that the index numbers in
// the switch statement correspond to the order of the select options in the form.
selectedIndex = tabForm.<%=options.OVERWRITE_WORKITEM%>.selectedIndex;
switch (selectedIndex)
{
case 0:
masterForm.<%=options.OVERWRITE_WORKITEM%>.value = <%=pvcs.cmd.PvcsConst.PROMPT_USER%>
break;
case 1:
masterForm.<%=options.OVERWRITE_WORKITEM%>.value = <%=pvcs.cmd.PvcsConst.ANSWER_YES%>
break;
case 2:
masterForm.<%=options.OVERWRITE_WORKITEM%>.value = <%=pvcs.cmd.PvcsConst.ANSWER_NO%>
break;
default:
alert('Bad selected index for OVERWRITE_WORKITEM: ' + selectedIndex);
}
if(<%=isModelInAffect%>){
if (document.general_form.ENABLE_LOOKUP.checked==false){
masterForm.<%=options.LOOKUP_REVISION%>.value = "<%=pvcs.cmd.PvcsConst.NOLOOKUP%>";
}
}
else{
masterForm.<%=options.LOOKUP_REVISION%>.value = "<%=pvcs.cmd.PvcsConst.REVISION%>";
}
// Copy the fields from the Advanced form
tabForm = getForm("advanced_form", "advanced_layer")
copyFormData(masterForm, tabForm);
// Encode form data using UTF8.
encodeFormData(masterForm, document.UTF8Encode);
return true;
}
checkout.jsp 修改部分:添加以下代码后,我收到上述错误,如果我删除它,它工作正常!!!!!!
<tr> <td>Project:</td> <td> <select id="projn" name="projn"> <option value="volvo">Volvo</option> <option value="saab" SELECTED>Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select> </td> </tr>
部分代码
<DIV ID="general_layer" class="visiblelayer" ALIGN="left"><!-- general layer-->
<FORM NAME="general_form" METHOD="post" ACTION="" onSubmit="return genSubmit(this)">
<BR>
<TABLE BORDER="0">
<TR VALIGN="top">
<TD><%=I18n.getStr(jspFileName,"CHECK_OUT_TO","Check Out To:")%></TD>
<%-- <TD><INPUT TYPE="text" NAME="<%=options.WORKING_FOLDER%>" VALUE="<%=options.getStringPropertySafe(options.WORKING_FOLDER)%>" SIZE="40" MAXLENGTH="254"> <INPUT TYPE="button" VALUE=" ... "></TD> --%>
<TD><%=HtmlTagHelper.writeBrowseTag("general_form",
options.WORKING_FOLDER,
options.getStringPropertySafe(options.WORKING_FOLDER),
I18n.getStr(jspFileName, "BROWSE_TITLE_KEY", "Select Workfile Location"),
browseType,
45)%>
</TD>
</TR>
<%if (projectSelection || multiSelect)
{%>
<TR VALIGN="top">
<TD></TD>
<TD><INPUT TYPE="checkbox" NAME="<%=options.USE_WORKPATH_ATTRIBUTE%>" VALUE="false"><%=I18n.getStr(jspFileName,"CHECK_OUT_USING_PROJECT_HIERARCHY",
"Check out using project hierarchy instead of workfile location(s)")%></TD>
</TR>
<%}%>
<tr>
<td>Project:</td>
<td>
<select id="projn" name="projn">
<option value="volvo">Volvo</option>
<option value="saab" SELECTED>Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</td>
</tr>
<tr>
<td>Developer:</td>
<td>col2</td>
</tr>
<tr>
<td>Required Duration:</td>
<td><input type="text" ID="ReqDuration" name="ReqDuration" value="5"/>Days</td>
</tr>
<tr>
<td>RFA No:</td>
<td><input type="text" ID="RFANO" name="RFANO" value="10256"/></td>
</tr>
<tr>
<td>Prefered checkout location:</td>
<td><input type="text" ID="LocationPreFix" name="LocationPreFix" value="C:\projects\"/>
<input type="button" value="Generate Checkout Link" onClick="generateCheckout()" /></td>
</tr>
<TR VALIGN="top">
<TD><%=I18n.getStr(jspFileName,"CHECKOUT_REVISION","Revision:")%></TD>
<TD><INPUT TYPE="text" NAME="<%=options.REVISION%>" VALUE="<%=revision%>" SIZE="20" MAXLENGTH="254" onChange="revisionChanged()">
<input type="button" value=" ... " onClick="window.opener.parent.browseForLabel(document.master_form,document.general_form.<%=options.REVISION%>,false,true,'<%=pvcs.vm.servlet.BrowseLabelFrameJspHelper.REVISION_VIEW%>');" onFocus="checkRevision();"/>
</TD>
</TR>
<TR VALIGN="top">
<TD><%=I18n.getStr(jspFileName,"IF_WORKFILE_EXISTS","If Workfile Exists:")%></TD>
<TD>
<SELECT name="<%=options.OVERWRITE_WORKITEM%>">
<OPTION <%if (overWriteWorkItem == pvcs.cmd.PvcsConst.PROMPT_USER) {%> SELECTED <%}%>><%=I18n.getStr(jspFileName,"IF_EXISTS_PROMPT","Prompt")%>
<OPTION <%if (overWriteWorkItem == pvcs.cmd.PvcsConst.ANSWER_YES) {%> SELECTED <%}%>><%=I18n.getStr(jspFileName,"IF_EXISTS_OVERWRITE","Overwrite")%>
<OPTION <%if (overWriteWorkItem == pvcs.cmd.PvcsConst.ANSWER_NO) {%> SELECTED <%}%>><%=I18n.getStr(jspFileName,"IF_EXISTS_DONT_OVERWRITE","Do not overwrite")%>
</SELECT>
</TD>
</TR>
<%
if (devPromoGroups != null)
{
%>
<TR VALIGN="top">
<TD><%=I18n.getStr(jspFileName,"CHECKOUT_PROMOTION_GROUP","Promotion Group:")%></TD>
<TD>
<SELECT name="<%=options.TO_PROMOTION_GROUP%>">
<% for (int i=0; i < devPromoGroups.length; i++)
{
%>
<OPTION><%=devPromoGroups[i]%>
<% }%>
</SELECT>
</TD>
</TR>
<% }%>
<%if (showAssociationsButton)
{%>
<tr>
<td>
<br>
<INPUT TYPE="button" VALUE="<%=I18n.getStr(jspFileName,"AssociateSCRS","Associate Issues")%>" onClick="onAssociateSCRs()">
</td>
</tr>
<% }%>
<%-- START Added by Vamsi on 22nd May 2003
This is done as part of the Vm_secondary_performance_functional_spec. The below code is
moved from the Advanced Tab.
--%>
<TR VALIGN="top">
<TD COLSPAN="3">
<INPUT TYPE="checkbox" NAME="<%=options.CHECKOUT_BY_DATE_RADIO_CHOICE%>" <%if (options.getBooleanPropertySafe(options.ONLY_IF_REVISION_NEWER, false)) {%> CHECKED <%}%> VALUE="<%=options.CHECKOUT_BY_DATE_RADIO_ONLY_IF_REVISION_NEWER%>"><%=I18n.getStr(jspFileName,"GET_REVISION_NEWER_THAN_WORK_FILE","Get only if revision newer than workfile")%>
</TD>
</TR>
<%
if (devPromoGroups != null )
{
%>
<TR VALIGN="top">
<TD COLSPAN="3">
<input type="checkbox" NAME="ENABLE_LOOKUP" <%if (!disableLookup) {%> CHECKED <%}%> onClick="toggleLookupOptions();"><%=I18n.getStr(jspFileName,"LOOKUP_ENABLE_LABEL","Force revision lookup")%><br>
</TD>
</TR>
<TR VALIGN="top">
<TD COLSPAN="3">
<input type="radio" name="<%=options.LOOKUP_REVISION%>" value="<%=pvcs.cmd.PvcsConst.REVISION%>" <%if (!lookupByGroup) {%> CHECKED <%}%> <%if (disableLookup) {%> DISABLED <%}%>> <%=I18n.getStr(jspFileName,"LOOKUP_REV_LABEL","Based on Revision")%><br>
<input type="radio" name="<%=options.LOOKUP_REVISION%>" value="<%=pvcs.cmd.PvcsConst.GROUP%>" <%if (lookupByGroup) {%> CHECKED <%}%> <%if (disableLookup) {%> DISABLED <%}%>> <%=I18n.getStr(jspFileName,"LOOKUP_GROUP_LABEL","Based on Promotion Group")%>
</TD>
</TR>
<%}%>
<%-- END --%>
</TABLE>
<BR>
</FORM>
</DIV>