By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Add Row in Grid using Javascript...

P: 3
Hi,

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


Expand|Select|Wrap|Line Numbers
  1.     function addCritr(curno){
  2.         var f = document.frmC5W002;
  3.  
  4.         // check val 1 & val 2 range
  5.         if (f.txt_val1.value!="" && f.txt_val2.value!=""){
  6.             if(parseInt(f.txt_val2.value)<=parseInt(f.txt_val1.value)){
  7.                 alert("Value 2 cannot be less than Value 1!")
  8.                 f.txt_val2.focus();
  9.                 return;
  10.             }
  11.         }
  12.         curno = curno + 1;
  13.         var grid = document.getElementById("CritrGrid");
  14.         var numRows = grid.rows.length; 
  15.  
  16.         grid.insertRow(curno);
  17.         grid.rows[curno].insertCell(0);
  18.         grid.rows[curno].insertCell(1);
  19.  
  20.         grid.rows[curno].cells[0].innerHTML = "<IMG SRC='../image/plussign.gif' onmouseover=this.style.cursor='hand' onclick='addCritr("+curno+")'>";
  21.  
  22.         grid.rows[curno].cells[1].innerText =  curno;
  23.  
  24. }
  25.  
  26.  
[HTML]<HTML>
<TABLE cellspacing="1" cellpadding="1" id="CritrGrid" class="grid" ALIGN="center" width="95%">
<THEAD class="header">
<TH width="2%">&nbsp;</TH>
<TH width="3%">SEQ</TH>
</THEAD>
<TR>
<TD>
<IMG SRC="../image/plussign.gif" onmouseover=this.style.cursor='hand' onclick="addCritr(1);">
</TD>
<TD>1</TD>
</TR>
</HTML>

[/HTML]
After i'd click on the "plussign.gif", 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 ;-))
Jan 25 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
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.
Jan 25 '08 #2

P: 3
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?
Jan 29 '08 #3

acoder
Expert Mod 15k+
P: 16,027
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.
Jan 29 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.