Sunday, June 24, 2012

Javascript onclick Display n number of textbox


<SCRIPT language="javascript">
function addRow(tableID)
{
var table = document.getElementById(tableID);

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

var colCount = table.rows[0].cells.length;
var cnt = document.getElementById('cntdiv').innerHTML;
document.getElementById('cntdiv').innerHTML=parseInt(cnt) + 1;
for(var i=0; i<colCount; i++)
{
var newcell = row.insertCell(i);
//alert("error_"+cnt);
newcell.innerHTML = '<div id="error_'+cnt+'"></div>'+table.rows[0].cells[i].innerHTML;
switch(newcell.childNodes[0].type)
{
case "text":
newcell.childNodes[0].value = "";
break;
case "radio":
newcell.childNodes[0].checked = false;
break;
case "textarea":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
cnt++;
}
</SCRIPT>
<div id='cntdiv' style="display:none;"></div>
<form action="/index.php?option=com_business" method="post" id="josForm" name="adminForm" class="form-validate"
enctype="multipart/form-data">
  <table id="dataTable" border="0">
    <div id="error_0" align="center"></div>
    <tr>
      <td><label>Category Name</label>
        <span class="strk">*</span>
        <div class="clr"></div>
        <input type="text" title="Menu Category" name="name[]" id="name[]" class="textbox validate(required)" style="width: 245px;" value="">
        <div class="clr"></div>
        <br>
      </td>
    </tr>
  </table>
  <div class="rs">
    <INPUT type="button" value="Add Category" onClick="addRow('dataTable')" />
  </div>
</form>

No comments:

Post a Comment

Please mention your comments.......