There does seem to be quite a bit of repetition in the code. Perhaps you could shorten the code, e.g. the insert cells could be converted to a function which takes the attribute parameters and sets them:
[code=javascript]oCell = row.insertCell( 0);
var el = document.create Element('input' );
el.type="text";
el.size="5";
el.value=taskno ;
oCell.appendChi ld(el);
oCell.innerHTML =oCell.innerHTM L;[/code]could be converted to:
[code=javascript]createCell(row, 0,"text","5",ta skno);
function createCell(row, rowno, type, size, val) {
oCell = row.insertCell( rowno);
var el = document.create Element('input' );
el.type=type;
el.size=size;
el.value=val;
oCell.appendChi ld(el);
oCell.innerHTML =oCell.innerHTM L;
}[/code]and repeat for the other cells.
The parts which are similar for the task and sub-tasks could be combined into one function with parameters to differentiate between the two.
There does seem to be quite a bit of repetition in the code. Perhaps you could shorten the code, e.g. the insert cells could be converted to a function which takes the attribute parameters and sets them:
[code=javascript]oCell = row.insertCell( 0);
var el = document.create Element('input' );
el.type="text";
el.size="5";
el.value=taskno ;
oCell.appendChi ld(el);
oCell.innerHTML =oCell.innerHTM L;[/code]could be converted to:
[code=javascript]createCell(row, 0,"text","5",ta skno);
function createCell(row, rowno, type, size, val) {
oCell = row.insertCell( rowno);
var el = document.create Element('input' );
el.type=type;
el.size=size;
el.value=val;
oCell.appendChi ld(el);
oCell.innerHTML =oCell.innerHTM L;
}[/code]and repeat for the other cells.
The parts which are similar for the task and sub-tasks could be combined into one function with parameters to differentiate between the two.
Thank You for youe suggestion sir, I will follow it.
Regards
Ramanan Kalirajan
My Requirement completed code, but i can't optimize the code
[HTML]<html>
<head>
<script language="javas cript">[/html]
[code=javascript]var taskno=0;
var ROW_BASE=1;
function addTask()
{
var oTable=document .getElementById ('myTable');
var lastRow = oTable.rows.len gth;
var row=oTable.inse rtRow(lastRow);
For example, the following:[code=javascript]
function addTask()
{
var oTable=document .getElementById ('myTable');
var lastRow = oTable.rows.len gth;
var row=oTable.inse rtRow(lastRow);
//Start Date
oCell = row.insertCell( 5);
var el5 = document.create Element('input' );
el5.type="text" ;
oCell.appendChi ld(el5);
oCell.innerHTML =oCell.innerHTM L;
//End Date
oCell = row.insertCell( 6);
var el6 = document.create Element('input' );
el6.type="text" ;
oCell.appendChi ld(el6);
oCell.innerHTML =oCell.innerHTM L;
//Total Hrs
oCell = row.insertCell( 7);
var el7 = document.create Element('input' );
el7.type="text" ;
oCell.appendChi ld(el6);
oCell.innerHTML =oCell.innerHTM L;
}[/code] could be converted to:
[code=javascript]function createCell(row, rowno, type, size, val, onc) {
oCell = row.insertCell( rowno);
var el = document.create Element('input' );
el.type=type;
if (size) el.size=size;
el.value=val;
if (onc) el.onclick = onc;
oCell.appendChi ld(el);
oCell.innerHTML =oCell.innerHTM L;
}
function addTask()
{
var oTable=document .getElementById ('myTable');
var lastRow = oTable.rows.len gth;
var row=oTable.inse rtRow(lastRow);
//create WBS Cell
createCell(row, 0,"text","5",ta skno);
//Task Name
createCell(row, 1,"text","25"," ");
//Adding SubTask
createCell(row, 2,"button",null ,"Add Sub task","removeTh is(this)");
//...and so on...
}[/code]I've not tested this, but it gives you an idea.
By tomorrow I am finishing this project. Surely I will try in this method what you had suggested now, Thank you Sir. Really this forum is helpful for me to develop my skills.
Regards
Ramanan Kalirajan
Last edited by acoder; Mar 20 '08, 05:01 PM.
Reason: removed quote
Comment