Add Texfield in Html Table through Javascript.

<script type="text/javascript">
function addRow(tableID) {
        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;
        var row = table.insertRow(rowCount);
        var cell1 = row.insertCell(0);
         cell1.innerHTML = rowCount;
        var cell2 = row.insertCell(1);
        cell2.innerHTML = "<input type='text' name='key[]' style='width:140px;'>";
        var cell3 = row.insertCell(2);
        cell3.innerHTML = "<input type='text' name='descr[]' style='width:140px;'>";
        var cell4 = row.insertCell(3);
        cell4.innerHTML = "<input type='text' name='city[]' style='width:140px;'>";
        var cell5 = row.insertCell(4);
        cell5.innerHTML = "<input type='text' name='address[]' style='width:140px;'>";
 var cell6 = row.insertCell(5);
        cell6.innerHTML = "<input type='text' name='address1[]' style='width:140px;'>";
        var cell7 = row.insertCell(6);
        cell7.innerHTML = "<input type='text' name='zip[]' style='width:140px;'>";
        var cell8 = row.insertCell(7);
        cell8.innerHTML = "<input type='text' name='municipal[]' style='width:140px;'>";
       
    }
function save()
{
document.getElementById("cust").submit();
}

function saveToDatabase(editableObj,column,id) {
$(editableObj).css("background","#FFF url(loaderIcon.gif) no-repeat right");
$.ajax({
url: "saveedit.php",
type: "POST",
data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
success: function(data){
$(editableObj).css("background","#FDFDFD");
}      
   });
}
</script>




<table cellspacing="0" style="font-size:15px;" width="100%" align="center" id="sl">
 
 <p class="a">Custom Subsidiary</p>
 <INPUT type="button" value="Add" onclick="addRow('sl')" style="font-family: 'icomoon';
    font-size: 12px;content: \e608;"/>
  <tr style="" width="100%">
  <th style="border-bottom: black 2px solid;"></th>
 

  <th style="border-bottom: black 2px solid;text-align:left;" valign="left">Key</th>
  <th style="border-bottom: black 2px solid;text-align:left;" align="left">Description</th>

  <th style="border-bottom: black 2px solid;text-align:left;" align="left">City</th>
  <th style="border-bottom: black 2px solid;text-align:left;" align="left">Address</th>
  <th style="border-bottom: black 2px solid;text-align:left;" align="left">Address</th>
 <th style="border-bottom: black 2px solid;text-align:left;" align="left">Zipcode</th>
 <th style="border-bottom: black 2px solid;text-align:left;" align="left">Municipal</th>


  </tr>
  <?php
  $c=1;
  $sq=mysql_query("select * from subsidiaryledger");
  while($re=mysql_fetch_array($sq))
  {
  ?>
  <tr>
  <td  align="left"><?php echo $c;?></td>
  <td style="font-family: erpag,Segoe UI;
    font-weight: bold;
    font-size: 11px;" align="left" contenteditable="true" onBlur="saveToDatabase(this,'keyss','<?php echo $re[0]; ?>')"><?php echo $re[1];?></td>
  <td style="font-family: erpag,Segoe UI;
    font-weight: bold;
    font-size: 11px;" align="left" contenteditable="true" onBlur="saveToDatabase(this,'description','<?php echo $re[0]; ?>')"><?php echo $re[2];?></td>
  <td style="font-family: erpag,Segoe UI;
    font-weight: bold;
    font-size: 11px;" align="left" contenteditable="true" onBlur="saveToDatabase(this,'city','<?php echo $re[0]; ?>')"><?php echo $re[3];?></td>
  <td style="font-family: erpag,Segoe UI;
    font-weight: bold;
    font-size: 11px;" align="left" contenteditable="true" onBlur="saveToDatabase(this,'address','<?php echo $re[0]; ?>')"><?php echo $re[4];?></td>
<td style="font-family: erpag,Segoe UI;
    font-weight: bold;
    font-size: 11px;" align="left" contenteditable="true" onBlur="saveToDatabase(this,'address1','<?php echo $re[0]; ?>')"><?php echo $re[5];?></td>
<td style="font-family: erpag,Segoe UI;
    font-weight: bold;
    font-size: 11px;" align="left" contenteditable="true" onBlur="saveToDatabase(this,'zipcode','<?php echo $re[0]; ?>')"><?php echo $re[6];?></td>
<td style="font-family: erpag,Segoe UI;
    font-weight: bold;
    font-size: 11px;" align="left" contenteditable="true" onBlur="saveToDatabase(this,'municipal','<?php echo $re[0]; ?>')"><?php echo $re[7];?></td>
<td><a href="subsidiaryledger.php?id=<?php echo $re[0];?>&st=del"><img src="delete.png"></a></td>
  </tr>
  <?php
$c++;  }
  ?>
 
 
 

  </table>

Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.