Add Row in Grid using Javascript...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jacelyn2211
    New Member
    • Jan 2008
    • 3

    Add Row in Grid using Javascript...

    Hi,

    i have a grid / table in html form as followings code,:-


    [CODE=javascript] function addCritr(curno){
    var f = document.frmC5W 002;

    // check val 1 & val 2 range
    if (f.txt_val1.val ue!="" && f.txt_val2.valu e!=""){
    if(parseInt(f.t xt_val2.value)< =parseInt(f.txt _val1.value)){
    alert("Value 2 cannot be less than Value 1!")
    f.txt_val2.focu s();
    return;
    }
    }
    curno = curno + 1;
    var grid = document.getEle mentById("Critr Grid");
    var numRows = grid.rows.lengt h;

    grid.insertRow( curno);
    grid.rows[curno].insertCell(0);
    grid.rows[curno].insertCell(1);

    grid.rows[curno].cells[0].innerHTML = "<IMG SRC='../image/plussign.gif' onmouseover=thi s.style.cursor= 'hand' onclick='addCri tr("+curno+")'> ";

    grid.rows[curno].cells[1].innerText = curno;

    }

    [/CODE]

    [HTML]<HTML>
    <TABLE cellspacing="1" cellpadding="1" id="CritrGrid" class="grid" ALIGN="center" width="95%">
    <THEAD class="header">
    <TH width="2%">&nbs p;</TH>
    <TH width="3%">SEQ</TH>
    </THEAD>
    <TR>
    <TD>
    <IMG SRC="../image/plussign.gif" onmouseover=thi s.style.cursor= 'hand' onclick="addCritr(1);">
    </TD>
    <TD>1</TD>
    </TR>
    </HTML>

    [/HTML]
    After i'd click on the "plussign.g if", it will call the function "addCritr() ", and add 1 more row in grid "CritrGrid" using javascript (grid.rows[curno].insertCell(0); follow by grid.rows[curno].cells[0]....) ..

    My question is after i'd add so many rows on the grid, and after i refresh the web page, all of the rows that i added using the javascript function will be become blank again..

    how would i keep those rows & values after refresh the web page???


    Anyone know bout these? Pls help!!!!~

    Many Thanks ;-))
    Last edited by acoder; Jan 25 '08, 09:45 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    You will need to use cookies to save the number of rows added and then when the page loads, add the number of rows that have been saved in the cookies. Read about cookies here.

    Comment

    • jacelyn2211
      New Member
      • Jan 2008
      • 3

      #3
      Originally posted by acoder
      Welcome to TSDN!

      You will need to use cookies to save the number of rows added and then when the page loads, add the number of rows that have been saved in the cookies. Read about cookies here.


      in this case, cookies really can work ..
      but it have d limitation also.. because cookies file size got limit, for eg : IE can store up to 4096 bytes file size in a cookies file.

      is there any way to increase / limit d cookies file size?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by jacelyn2211
        in this case, cookies really can work ..
        but it have d limitation also.. because cookies file size got limit, for eg : IE can store up to 4096 bytes file size in a cookies file.

        is there any way to increase / limit d cookies file size?
        It can work because you only need to save the minimum information required to reconstruct the table again, e.g. no need to save the img string information because that is repeated for each row.

        Comment

        Working...