2010-03-04 6 views
1

이 버튼을 누르면 새 HTML 행이 추가됩니다. 이 행에는 cboOffsetGroup 및 cboOffsetType이라는 두 개의 콤보 상자가 있습니다. cboOffsetGroup에서 선택된 항목에 따라 cboOffsetType의 옵션이 변경됩니다. Javascript에서 refreshPage() 함수를 사용하여이 작업을 수행합니다. 그것은 첫 번째 행에서 잘 작동하지만 이후에 추가 된 행에서 cboOffsetType에 적절한 옵션을 채울 수 있도록 refreshPage() funciton을 호출하는 방법을 파악할 수 없습니다. 이 문제에 대한 도움을 주시면 감사하겠습니다. 나는 이것에 초심자이고, 이것이 최고 부호가 아닐지도 모르다는 것을주의한다, 그러나 나가 일해야하는 무슨을주의하십시오. 감사!동적으로 새로 추가 된 행을 새로 고치고 채우기

<% 
Dim CN, RS, vIndexOffset, vOffsetGroup 

Set CN = GetDataConnection 

vIndexOffset = Request.Form("txtOffsetIndex") 
%> 

<body> 
<form name="frmExceptionInput" id="frmExceptionInput" method="post"> 
<input type="hidden" name="txtAction" id="txtAction" value=""> 

<table width="50%" id="tblOffsetDetail"> 
<tbody> 
    <tr> 
     <td colspan="2"> 
     <input type="button" class="button" value= "Add New Item" id="btnNewOffsetItem" name="btnNewOffsetItem" onClick="javascript:addNewOffsetItem();"> 
     <input type="hidden" id="txtOffsetIndex" name="txtOffsetIndex" value="1"> 
    </td> 
    </tr> 
    <tr> 
     <td> 
      <p> 
      <select name="cboOffsetGroup1" id="cboOffsetGroup1" onChange="refreshPage();"> 
       <option value="0"></option> 
       <% 
       Set RS = CN.Execute ("spSelectGroup") 
       If Not RS.EOF Then 
        Do While Not RS.EOF 
         %> 
         <option value='<%= RS("offsetGroupID")%>'<%If RS("offsetGroupID") = Request.Form("cboOffsetGroup" & vIndexOffset) Then Response.Write " selected"%>><%= RS("offsetGroup")%></option>  
         <% 
         'Get next record 
         RS.MoveNext 
        Loop 
       End If 
       %> 
      </select> 
      </p>   
     </td> 
     <td> 
      <p> 
      <select name="cboOffsetType1" id="cboOffsetType1"> 
      <% 
      'If the user changes the combo box selected, set vOffsetGroup = the value selected by the user on the page. 
      If Request.Form("txtAction") = "Change Selection" Then 
       vOffsetGroup = Request.Form("cboOffsetGroup" & vIndexOffset) 
      End If 
      %> 
      <option value="0"></option> 
      <% 
      Set RS = CN.Execute ("spSelectType @vOffsetGroup='" & vOffsetGroup & "'") 
      If Not RS.EOF Then 
       Do While Not RS.EOF 
        %> 
        <option value='<%= RS("offsetItemTypeID")%>'<%If Request.Form("cboOffsetType1") = RS("offsetItemTypeID") Then Response.Write "selected"%>><%= RS("offsetItemType")%></option> 
        <% 
        'Get next record 
        RS.MoveNext 
       Loop 
      End If 
      %> 
      </select> 
      </p> 
     </td> 
    </tr> 
</tbody> 
</table> 

</form> 
</body> 

<script language="javascript"> 

function refreshPage() 
{ 
    var refreshPage = document.getElementById("frmExceptionInput"); 

    //If this function is called, the value of txtAction will become "Change Selection." 
    document.getElementById("txtAction").value = "Change Selection"; 

    refreshPage.submit(); 
} 

//Display additional rows. 
function addNewOffsetItem() 
{ 
    var iX = document.getElementById("txtOffsetIndex").value; 
    iX ++; 
    document.getElementById("txtOffsetIndex").value = iX; 

    var tbl = document.getElementById("tblOffsetDetail").getElementsByTagName("TBODY")[0]; 
    var tr = document.createElement("TR"); 
    tbl.appendChild(tr); 

    //cboOffsetGroup1 
    var tdOffsetGroup = document.createElement("TD"); 
    tr.appendChild(tdOffsetGroup); 

    var p = document.createElement("P"); 
    tdOffsetGroup.appendChild(p); 

    var cboOffsetGroup = document.createElement("select"); 
    p.appendChild(cboOffsetGroup); 

    cboOffsetGroup.id = "cboOffsetGroup" + iX; 
    cboOffsetGroup.setAttribute('name','cboOffsetGroup' + iX); 

    var cboOffsetGroup1 = document.getElementById("cboOffsetGroup1"); 
    var i = 0; 

    for (i = 0; i < cboOffsetGroup1.children.length; i++) 
     { 
      var opt = document.createElement("option"); 
      opt.value = cboOffsetGroup1 [i].value; 
      opt.innerText = cboOffsetGroup1 [i].innerText; 
      cboOffsetGroup.appendChild(opt); 
     } 

    //cboOffsetType1 
    var tdOffsetType = document.createElement("TD"); 
    tr.appendChild(tdOffsetType); 

    var p = document.createElement("P"); 
    tdOffsetType.appendChild(p); 

    var cboOffsetType = document.createElement("select"); 
    p.appendChild(cboOffsetType); 

    cboOffsetType.id = "cboOffsetType" + iX; 
    cboOffsetType.setAttribute('name','cboOffsetType' + iX); 

    var cboOffsetType1 = document.getElementById("cboOffsetType1"); 
    var i = 0; 

    for (i = 0; i < cboOffsetType1.children.length; i++) 
     { 
      var opt = document.createElement("option"); 
      opt.value = cboOffsetType1 [i].value; 
      opt.innerText = cboOffsetType1 [i].innerText; 
      cboOffsetType.appendChild(opt); 
     } 
} 

</script> 
</html> 

답변

1

이러한 종류의 작업에는 JQuery를 사용하는 것이 좋습니다.

http://api.jquery.com/add/

+0

나는 새로운 프로젝트에 향후 참조를 위해이로 볼 수 있지만, 정말이 프로젝트를 위해 그것을 할 시간이 없습니다. 현재 가지고있는 코드 내에서 솔루션을 찾고 있습니다. – SeanFlynn

관련 문제