How to add multiple rows?

    <tr>
        <td align="left" width="850">
            <table width="880px" border="1" cellpadding="5" cellspacing="0" bordercolor="#c1dde4" id="tbl_hotel">
                <tr class="accombg" >
                    <td width="312" rowspan="2" align="center"><strong>City/Place/Office Location</strong></td>
                    <td colspan="4" align="center"><strong>Date and Time </strong></td>
                    <td width="60" rowspan="2" align="center"><strong>No. of Days</strong></td>
                    <td colspan="2" align="center" ><strong>Cost/day</strong></td>
                </tr>
                <tr class="accombg" >
                    <td style="min-width:80px;max-width:80px;" align="center">Check-In<span class="redtext">*</span></td>
                    <td width="40" align="center">Check-In Time </td>
                    <td style="min-width:80px;max-width:80px;" align="center">Check-Out<span class="redtext">*</span></td>
                    <td width="40" align="center">Check-Out Time</td>
                    <td colspan="2" align="center">Amount/ Currency</td>
                </tr>
                <tr class="sectionbg" id="jsAccomodationDet">
                    <td>
                        <div id="tf_1" >
                            <input name="hotelname[2]" id="hotelname[2]" maxlength="35" type="text" style="width:250px;" value="" />
                        </div>
                    </td>
                    <td>
                        <div id="tf_2">
                            <!-- <input name="chkindate[2]" value="" type="text" id="chkindate" class="jsTravelCls" min="<?php echo date('Y-m-d'); ?>" /> -->
                            <input type="text" style="min-width:80px;max-width:80px;" name="chkindate[2]" value="" id="chkindate[2]" class="chkindate" onchange="calculate(this)"/>
                        </div>
                    </td>
                    
                    <td>
                        <div id="tz3">
                            <select name="time_zone3[2]">
                            <?php
                            foreach ($time_zone as $tme_zone) {
                                echo "<option value=\"" . $tme_zone . "\">" . $tme_zone . "</option>";
                            }
                            ?>
                            </select>
                        </div>
                    </td>

                    <td>                                            
                        <div id="tf_3">
                            <!-- <input name="chkoutdate[2]" type="text" id="chkoutdate" class="jsTravelCls" min="<?php echo date('Y-m-d'); ?>" onfocus="calculate(this)"/> -->
                            <input type="text" style="min-width:80px;max-width:80px;" name="chkoutdate[2]" value="" id="chkoutdate[2]" class="chkoutdate" onchange="calculate(this)"/>
                        </div>
                    </td>
                    
                    <td>
                        <div id="tz4">
                            <select name="time_zone4[2]">
                            <?php
                            foreach ($time_zone as $tme_zone) {
                                echo "<option value=\"" . $tme_zone . "\">" . $tme_zone . "</option>";
                            }
                            ?>
                            </select>
                        </div>
                    </td>

                    <td>
                        <div id="tf_4">
                            <input name="no_of_days[2]" maxlength="3" id="no_of_days[2]" type="text" style="width:60px;" value=""/>
                        </div>
                    </td>

                  <td width="80" >
                    <div id="tf_5"  style="width:80px">
                        <input name="perdym[2]" maxlength="7" id="perdym[2]" type="text" style="width:80px;" value="" onkeypress="return restrictCharacters(this, event, digitsOnly);" title="To be updated by Secretary" />
                    </div>
                  </td>

                  <td width="60" align="right">
                    <div id="t_cost3">
                        <select name="t_cost_2[2]"  style="width:60px">
                            <!-- <?php
                            foreach ($currency as $curr) {
                                echo "<option value=\"" . $curr . "\">" . $curr . "</option>";
                            }
                            ?> -->
                        <?php
                            $conn = mysqli_connect('localhost', 'root', '', 'tools_bta');                                      
                            $currency = mysqli_query($conn, "SELECT * FROM dropdown_options WHERE dropdown_id = '4' AND is_active = 1 ORDER BY option_key asc");                                            
                            if($currency){
                                                                            foreach ($currency as $cc) {
                                if ($cc['option_key'] == "INR"){
                                    $default = "selected";
                                }else{
                                    $default = "";
                                }
                                echo "<option ".$default." value=\"" . $cc['option_key'] . "\">" . $cc['option_key'] . "</option>";
                            }
                                // foreach ($currency as $cc) {
                                //     echo "<option value=\"" . $cc['option_key'] . "\">" . $cc['option_key'] . "</option>";
                                // }
                            }
                        ?>
                        </select>
                    </div>
                   </td>
                </tr>
            </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table align="left">
                                    <tr>
                                        <td align="left">
                                            <a href="javascript:void(0)" class="addlinks" onclick="addHotelRow('tbl_hotel')">+ Insert Row</a>                                                            </td>
                                        <td align="left">
                                            <a href="javascript:void(0)" class="addlinks" onclick="delIt('tbl_hotel')"> - Delete Row </a>
                                            </td>
                                    </tr>
                                </table>
                                </td>
                        </tr>


function addHotelRow(tableID) {
  var $j = jQuery.noConflict();
 /* $j(".chkindate").datepicker("destroy");
  $j(".chkoutdate").datepicker("destroy");*/
  var table = document.getElementById(tableID);

  var rowCount = table.rows.length;
  var row = table.insertRow(rowCount);

  var colCount = table.rows[2].cells.length;

  for(var i=0; i<colCount; i++) {

    var newcell = row.insertCell(i);

    newcell.innerHTML = table.rows[2].cells[i].innerHTML;
    //alert(newcell.childNodes);
    switch(newcell.childNodes[2].type) {
      case "text":
        e1 = newcell.childNodes[2];
        e1.value = "";
        if (e1.name=='hotelname[2]'){
              el.id = 'hotelname[2]' + i;
          }else if(e1.name=='chkindate[2]'){
              el.id = 'chkindate[2]' + i;
          }
          else if(e1.name=='chkoutdate[2]'){
              el.id = 'chkoutdate[2]' + i;
          }
          else if(e1.name=='time_zone4[2]'){
              el.id = 'time_zone4[2]' + i;
          }
          else if(e1.name=='no_of_days[2]'){
              el.id = 'no_of_days[2]' + i;
          }
          else if(e1.name=='perdym[2]'){
              el.id = 'perdym[2]' + i;
          }
          else if(e1.name=='t_cost_2[2]'){
              el.id = 't_cost_2[2]' + i;
          }
          // newcell.childNodes[2].value = "";
          break;
      case "checkbox":
          newcell.childNodes[2].checked = false;
          break;
      case "select-one":
          newcell.childNodes[2].selectedIndex = 2;
          break;
          
    }
  }

var dateAssignedId = Math.round(new Date().getTime() + (Math.random() * 100));
var dateDueId = Math.round(new Date().getTime() + (Math.random() * 100));
  $(row).find('.chkindate')[0].id = dateAssignedId; 
  $(row).find('.chkoutdate')[0].id = dateDueId;
  
  $j(".chkindate").datepicker({
    dateFormat: "dd-mm-yy",
    minDate: new Date()
});
  $j(".chkoutdate").datepicker({
    dateFormat: "dd-mm-yy",
    minDate: new Date()
});
}

select a row, hit ctrl+d (for duplicate)

Can you please elaborate? Where should I use such or is there anything wrong in the code?

Sponsor our Newsletter | Privacy Policy | Terms of Service