将选定的复选框从弹出窗口传递到动态表格上的文本输入

时间:2016-08-10 13:45:56

标签: javascript html checkbox

我有一个动态表,用户通过单击添加行按钮添加行。在行中我有一个“选择范围”按钮,打开一个新窗口,其中包含复选框,我正在尝试将所有选中复选框的值发布到父页面的动态表格中的文本输入中。 Dynamic Table Pic Select Scope Pic我知道只使用javascript就可以实现这一点,我觉得我已经阅读了所有内容。无论出于何种原因,虽然它没有将复选框值传回文本输入。

家长网页代码

<h2>Please fill in the information below</h2>
        <form action="pmUnitCreate.php" method="post">
            <p>Click the Add button to add a new row. Click the Delete button to Delete last row.</p>

            <input type="button" id="btnAdd" class="button-add" onClick="addRow('myTable')" value="Add"/>
             <input type="button" id="btnDelete" class="button-delete" onClick="deleteRow('myTable')" value="Delete"/>



            <br>

            <table id="myTable" class="form">

                 <tr id="heading">
                <th><b><font size="4">Job Number</font></b></th>
                <th><b><font size="4">Unit Number</font></b></th>
                <th><b><font size="4">Job Code</font></b></th>
                <th><b><font size="4">Model Number</font></b></th>
                <th><b><font size="4">Scope</font></b></th>
                </tr>   

                <tr id="tableRow">
                    <td>
                        <input type="text" name="JobNumber[]" value="<?php echo $JobNumber;?>" readonly>
                    </td>

                    <td>
                        <input type="text" name="UnitID[]" value="<?php echo $JobNumber;?>-01" readonly>
                    </td>

                    <td>
                        <select name="JobCode[]" style="background-color:#FFE68C" required>
                            <option></option>
                            <option>F</option>
                            <option>FS</option>
                            <option>PD</option>
                            </select>
                    </td>

                    <td>
                        <input type="text" name="ModelNumber[]" style="background-color:#FFE68C" required>
                    </td>

        <td>
            <button onclick="ScopeFunction()">Select Scope</button>
            <input type"text" name="Scope[]" style="background-color:#FFE68C">

        </td>

               </tr>

            </table>


            <script>

function incrementUnitId(unitId) {
    var arr = unitId.split('-');
    if (arr.length === 1) {return;} // The unit id is not valid;
    var number = parseInt(arr[1]) + 1;
    return arr[0] + '-' + (number < 10 ? 0 : '') + number;
    }

function addRow() {                
    var row = document.getElementById("tableRow"); // find row to copy
    var table = document.getElementById("myTable"); // find table to append to
    var clone = row.cloneNode(true); // copy children too
    row.id = "oldRow"; // We want to take the last value inserted
    clone.cells[1].childNodes[1].value = incrementUnitId(clone.cells[1].childNodes[1].value)
    table.appendChild(clone); // add new row to end of table
    }


function deleteRow() {
    document.getElementById("myTable").deleteRow(-1);
    }

 var popup;
 function SelectScope() {
 window.open("http://fisenusa.net/pm/pmSelectScope.php", "_blank",     "width=550,height=875");
popup.focus();
 }


     </script>

已编辑的弹出窗口代码

        <h1>Select Scope</h1>
<h3>Select all that apply</h3>
        <form name="childForm" id="updateParent();">

        <li><input type="checkbox" name="S1" value="100OA"/><font size="4">100OA</font>
            <input type="checkbox" name="S2" value="BTank"/><font size="4">BTank</font>
             <input type="checkbox" name="S3" value="WSEcon"/><font size="4">WSEcon</font>
              <input type="checkbox" name="S4" value="NetPkg"/><font size="4">NetPkg</font>
               <input type="checkbox" name="S5" value="CstmCtrl"/><font size="4">CstmCtrl</font>
               <br><br>
                <li><input type="checkbox" name="S6" value="CstmRef"/><font size="4">CstmRef</font>
                 <input type="checkbox" name="S7" value="CstmSM"/><font size="4">CstmSM</font>
                  <input type="checkbox" name="S8" value="CstmHV"/><font size="4">CstmHV</font>
                   <input type="checkbox" name="S9" value="CPCTrl"/><font size="4">CPCtrl</font>
                    <input type="checkbox" name="S10" value="DesiHW"/><font size="4">DesiHW</font>
                    <br><br>
            <li><input type="checkbox" name="S11" value="DigScroll"/><font size="4">DigScroll</font>
             <input type="checkbox" name="S12" value="DFGas"/><font size="4">DFGas</font>
              <input type="checkbox" name="S13" value="DWall"/><font size="4">DWall</font>
               <input type="checkbox" name="S14" value="MZ-DD"/><font size="4">MZ-DD</font>
                <input type="checkbox" name="S15" value="DPP"/><font size="4">DPP</font>
                 <input type="checkbox" name="S16" value="Encl"/><font size="4">Encl</font>
                 <br><br>
                  <li><input type="checkbox" name="S17" value="PlateHX"/><font size="4">PlateHX</font>
                   <input type="checkbox" name="S18" value="ERW"/><font size="4">ERW</font>
                    <input type="checkbox" name="S19" value="ERWModule"/><font size="4">ERWModule</font>
                     <input type="checkbox" name="S20" value="ERVMod"/><font size="4">ERVMod </font>
            <input type="checkbox" name="S21" value="EvapBP"/><font size="4">EvapBP</font>
            <br><br>
             <li><input type="checkbox" name="S22" value="PreEvap"/><font size="4">PreEvap</font>
              <input type="checkbox" name="S23" value="XP"/><font size="4">XP</font>
               <input type="checkbox" name="S24" value="Extended"/><font size="4">Extend</font>
                <input type="checkbox" name="S25" value="FanWall"/><font size="4">FanWall</font>
                 <input type="checkbox" name="S26" value="FillStat"/><font size="4">FillStat</font>
                  <input type="checkbox" name="S27" value="FFilt"/><font size="4">FFilt</font>
                  <br><br>
                   <li><input type="checkbox" name="S28" value="PFilt"/><font size="4">PFilt</font>
                    <input type="checkbox" name="S29" value="CarbFilt"/><font size="4">CarbFilt</font>
                     <input type="checkbox" name="S30" value="CustFilt"/><font size="4">CustFilt </font>
            <input type="checkbox" name="S31" value="MGH(H)"/><font size="4">MGH(H)</font>
             <input type="checkbox" name="S32" value="GHeat"/><font size="4">GHeat</font>
             <br><br>
              <li><input type="checkbox" name="S33" value="HighStatic"/><font size="4">HighStatic</font>
               <input type="checkbox" name="S34" value="HGBP"/><font size="4">HGBP</font>
                <input type="checkbox" name="S35" value="HGRH"/><font size="4">HGRH</font>
                 <input type="checkbox" name="S36" value="HPConv"/><font size="4">HPConv</font>
                  <input type="checkbox" name="S37" value="GFHumid"/><font size="4">GFHumid</font>
                  <br><br>
                   <li><input type="checkbox" name="S38" value="TOHumid"/><font size="4">TOHumid</font>
                    <input type="checkbox" name="S39" value="MHGRH"/><font size="4">MHGRH</font>
                     <input type="checkbox" name="S40" value="LowAF"/><font size="4">LowAF</font>
            <input type="checkbox" name="S41" value="LowAFSF"/><font size="4">LowAFSF</font>
             <input type="checkbox" name="S42" value="LowAmbient"/><font size="4">LowAmbient</font>
             <br><br>
              <li><input type="checkbox" name="S43" value="MEHeat(R)"/><font size="4">MEHeat(R)</font>
               <input type="checkbox" name="S44" value="MEHeat(I)"/><font size="4">MEHeat(I)</font>
                <input type="checkbox" name="S45" value="MGH(R)"/><font size="4">MGH(R)</font>
                 <input type="checkbox" name="S46" value="MGH(H)"/><font size="4">MGH(H)</font>
                  <input type="checkbox" name="S47" value="MtrRR"/><font size="4">MtrRR</font>
                  <br><br>
                   <li><input type="checkbox" name="S48" value="MotorGM"/><font size="4">MotorGM</font>
                    <input type="checkbox" name="S49" value="MZ-Mod"/><font size="4">MZ-Mod</font>
                     <input type="checkbox" name="S50" value="NatConv"/><font size="4">NatConv</font>
            <input type="checkbox" name="S51" value="OAFMS"/><font size="4">OAFMS</font>
             <input type="checkbox" name="S52" value="OSMotor"/><font size="4">OSMotor</font>
             <br><br>
              <li><input type="checkbox" name="S53" value="MZ-VAV"/><font size="4">MZ-VAV</font>
               <input type="checkbox" name="S54" value="Mon"/><font size="4">Mon</font>
                <input type="checkbox" name="S55" value="PumpPkg"/><font size="4">PumpPkg</font>
                 <input type="checkbox" name="S56" value="PipePkg"/><font size="4">PipePkg</font>
                  <input type="checkbox" name="S57" value="ServLite"/><font size="4">ServLite</font>
                  <br><br>
                   <li><input type="checkbox" name="S58" value="SparkRes"/><font size="4">SparkRes</font>
                    <input type="checkbox" name="S59" value="SSLube"/><font size="4">SSLube</font>
                     <input type="checkbox" name="S60" value="UVLights"/><font size="4">UVLights</font>
            <input type="checkbox" name="S61" value="VSComp"/><font size="4">VSComp</font>
            <br><br>
             <li><input type="checkbox" name="S62" value="LCVAV"/><font size="4">LCVAV</font>
              <input type="checkbox" name="S63" value="XFVAV"/><font size="4">XFVAV</font>
               <input type="checkbox" name="S64" value="WCCond"/><font size="4">WCCond</font>
                <input type="checkbox" name="S65" value="WSHPConv"/><font size="4">WSHPConv</font>
                 <input type="checkbox" name="S66" value="3RConv"/><font size="4">3RConv</font>
                 <br><br>
                  <li><input type="checkbox" name="S67" value="WiringGM"/><font size="4">WiringGM</font>
                   <input type="checkbox" name="S68" value="XFan"/><font size="4">XFan</font>
                    <input type="checkbox" name="S69" value="RFan"/><font size="4">RFan</font>
                     <input type="checkbox" name="S70" value="SFan"/><font size="4">SFan</font>
            <input type="checkbox" name="S71" value="OAHood"/><font size="4">OAHood</font>
            <br><br>
             <li><input type="checkbox" name="S72" value="XAHood"/><font size="4">XAHood</font>
              <input type="checkbox" name="S73" value="XALouver"/><font size="4">XALouver</font>
               <input type="checkbox" name="S74" value="OALouver"/><font size="4">OALouver</font>
                <input type="checkbox" name="S75" value="SteamCoil"/><font size="4">SteamCoil</font>
                 <input type="checkbox" name="S76" value="HWCoil"/><font size="4">HWCoil</font>
                 <br><br>
                  <li><input type="checkbox" name="S77" value="CHWCoil"/><font size="4">CHWCoil</font>
                   <input type="checkbox" name="S78" value="CondCoil"/><font size="4">CondCoil</font>
                    <input type="checkbox" name="S79" value="DXCoil"/><font size="4">DXCoil</font>
                     <input type="checkbox" name="S80" value="F&BP"/><font size="4">F&BP</font>
            <input type="checkbox" name="S81" value="Xfrmr"/><font size="4">Xfrmr</font>
            <br><br>
             <li><input type="checkbox" name="S82" value="WCCond"/><font size="4">WCCond</font>
              <input type="checkbox" name="S83" value="PLFrHX"/><font size="4">PlFrHX</li></font>
              <br>
              <input type="submit" value="Submit" />

        </form>



<script>

function updateParent() {    
s = "";
for (i = 0; i < 6; i++)
{
      chk = eval("self.document.childForm.t" + i);
      if (chk.checked)
            s += chk.value + ", ";
}
opener.document.parentForm.toppings.value = s;
self.close();

}

</script>

0 个答案:

没有答案