Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <script language="javascript">
- var i=0,ta="T",qa="Q",ra="R",k=0.0,j=0.0;
- function addRowToTable()
- {
- var tbl = document.getElementById('ad');
- var lastRow = tbl.rows.length - 6;
- var iteration = lastRow ;
- var row = tbl.insertRow(lastRow);
- var cellRight = row.insertCell(0);
- var el = document.createElement('input');
- el.type = 'text';
- el.name = 'I' + iteration;
- el.id = 'I' + iteration;
- el.size = 20;
- var cellRight1 = row.insertCell(1);
- var el1 = document.createElement('input');
- el1.type = 'text';
- el1.name = 'Q' + iteration;
- el1.id = 'Q' + iteration;
- el1.size = 14;
- el1.onblur='add1.focus()';
- var cellRight2 = row.insertCell(2);
- var el2 = document.createElement('input');
- el2.type = 'text';
- el2.name = 'R' + iteration;
- el2.id = 'R' + iteration;
- el2.size = 15;
- el2.onblur='res()';
- var cellRight3 = row.insertCell(3);
- var el3 = document.createElement('input');
- el3.setAttribute("type","text");
- el3.name = 'T' + iteration;
- el3.id = 'T' + iteration;
- el3.size = 15;
- el2.onkeypress=keyPressTes;
- document.getElementById("ti").value=iteration;
- cellRight.appendChild(el);
- cellRight1.appendChild(el1);
- cellRight2.appendChild(el2);
- cellRight3.appendChild(el3);
- el.focus();
- }
- function keyPressTes()
- {
- var key;
- if(window.event)
- key = window.event.keyCode;
- if(key == 08 )
- {
- alert("1");
- res();
- alert("2");
- }
- }
- function removeRowFromTable()
- {
- var tbl = document.getElementById('ad');
- var lastRow = tbl.rows.length;
- if (lastRow > 8)
- {
- var tt = lastRow - 7;
- ta="T";
- ta=ta+tt;
- tbl.deleteRow(lastRow - 7);
- document.getElementById("ti").value=lastRow - 8;
- ta="T";
- i--;
- }
- }
- </script>
- <script language='javascript'>
- function res()
- {
- for (var a=0; a<=i; a=a+1)
- {
- ta="T"+a;
- qa="Q"+a;
- ra="R"+a;
- var qt=document.getElementById(qa).value;
- var rt=document.getElementById(ra).value;
- var st=qt*rt;
- document.getElementById(ta).value=st;
- ta="T";
- qa="Q";
- ra="R";
- i++;
- qt=rt=st=0;
- }
- }
- </script>
- </head>
- <body>
- <form name="cnew">
- <table id="ad">
- <tr>
- <td width="123" align="left" height="1"><b>Item</b></td>
- <td width="86" align="left" height="1"><b>QUANTITY</b></td>
- <td width="86" align="left" height="1"><b>RATE</b></td>
- <td width="86" align="left" height="1"><b>TOTAL</b></td>
- </tr>
- <tr>
- <td width="123" align="left" height="5">
- <input type="text" name="I0" size="20" id="I0"></td>
- <td width="86" align="left" height="5">
- <input type="text" name="Q0" size="14" id="Q0"></td>
- <td width="86" align="left" height="5">
- <input type="text" name="R0" size="15" id="R0" onblur="res()"></td>
- <td width="86" align="left" height="5">
- <input type="text" name="T0" size="14" id="T0"></td>
- </tr>
- </table>
- <p align="center"><input type="button" id="add1" value="Add" onclick="addRowToTable()" tabindex="8" name="Add" />
- <input type="button" value="Remove" onclick="removeRowFromTable();" /> <input type="submit" value="Submit" name="B2">
- </form>
- </body>
- </html>