2013-04-24 64 views
0

我試圖根據我的需要修改PVCS(版本管理器)網頁版本。該產品在JSP中編寫。 我的問題是當我添加一個簡單的組合框我收到下面的錯誤,我不知道爲什麼?! 我調試了代碼,但我不能再次發生什麼問題,請幫我解決問題。'elements [value]'爲空或不是對象

Dialog.jsp

Line: 281 
Error: 'elements[...].value' is null or not an object 

功能,我收到錯誤: 請找:警報(姓名+ 「-A-」 + targetForm.elements [名] .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); 
     } 
    } 
} 

CHeckout.jsp - >在此文件中,位於以下行:

copyFormData(masterForm,tabForm);

masterForm爲null,這就是爲什麼我收到錯誤,但爲什麼?由於頁面工作正常,沒有我的組合框。

/* 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改質部分: 後我添加以下代碼我收到上述錯誤,如果刪除它,它工作正常!!!!!代碼

<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">&nbsp;<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&nbsp;Workfile&nbsp;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&nbsp;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"> 
    &nbsp;&nbsp;&nbsp;<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> 
    &nbsp;&nbsp;&nbsp;<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> 

回答

0

<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> 

一部分,我發現,在該頁面有幾個隱藏的申請是「copyFormData」功能讓所有的字段的副本,並將其存儲在那裏,所以這就是爲什麼我的新字段在那裏不可用,所以我收到空錯誤。