Add/Remove rows from Table

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2009
Posts: 83
Reputation: nish123 is an unknown quantity at this point 
Solved Threads: 0
nish123's Avatar
nish123 nish123 is offline Offline
Junior Poster in Training

Re: Add/Remove rows from Table

 
0
  #21
Jul 3rd, 2009
Originally Posted by sysel View Post
As I promised, I pulled out a piece of code and added it into the exaple, to show you a nice trick, how to create an option list very easy and clearly. As I added the <SELECT> column, it cause me to change somewhat the other routine, but I hope you can find and understand.

To show the powerful dynamic <OPTION> fill I adopted the function knockOut() for to trim the option list at each <SELECT> cleared of the used items. May be it is coded in 'lama' style, because in hurry :-) But for the understanding the javascript 1.2 it is sufficient. I hope.

I put here my version of code with a short PHP 'loader'. Your coding is very clear, good formated and commented. It gives you good chances to return back to your code and easy to repair it if necessary. Points for you! I see, I can easy introduce myself into the CSS from your code, too. Thanks.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <HTML><HEAD>
  3. <META http-equiv="content-type" content="text/html; charset=UTF-8">
  4. <meta http-equiv="Content-Script-Type" content="text/javascript">
  5. <TITLE>add/ed/del row</TITLE><?php ?> <?php /*comments*/?>
  6. <?php
  7. if($row=$_POST['row'])
  8. { foreach($row as $k => $v)
  9. { foreach($v as $kk => $vv)
  10. { $wor[$kk][$k]=$vv;
  11. };
  12. };
  13. } else $wor="";
  14.  
  15. $arrBrand=array(1=>"Electricity"
  16. ,2=>"Water"
  17. ,3=>"Gas"
  18. ,4=>"Appartement Rent"
  19. ,5=>"School Fee");
  20. /** $arrayBrand can be get from a database
  21. $res=mysql_query("SELECT distinct brand FROM table");
  22. $i=0;while($cols = mysql_fetch_row($dbResult))
  23. {$line[$i]="'$i':['$i++','".$cols[0]."']";
  24. }
  25. //*/
  26. foreach($arrBrand as $kk => $vv){ $line[]="'$kk':['$kk','$vv']";}
  27. $optOut="\n{".implode("\n,",$line)."}";
  28. ////oSel.length = 0;
  29. ?>
  30. <script>
  31. var i,d=document;
  32. /*********************************************************************/
  33. var oOpts = <?php print $optOut ?>; // move the set of Options into a JS object!
  34.  
  35. function add_option(what,where) // to define and add one Option
  36. { var nop = d.createElement('option');
  37. nop.innerHTML = what[1]; // nop.text does not accept MSIE
  38. nop.value = what[0];
  39. nop.title = nop.alt = what[0]; // showes the option value as 'bubble'
  40. where.appendChild(nop);
  41. }
  42. function fill_sell(oSel,oSet,oExept) // to clear and fill back the Option set
  43. { if(oExept==undefined)oExept={}; // except used ones
  44. var myVal='';if(oSel.length>1){ myVal=oSel.value; oSel.length = 1; }
  45. for(var l in oSet)
  46. { if( (l==myVal) || !(l in oExept) ) add_option(oSet[l],oSel);
  47. } oSel.value=myVal;
  48. }
  49. function knockOut(formChild) // to trim the each <select> option list
  50. { var selOpt=collect(formChild.form);
  51. var selAll = formChild.form.getElementsByTagName('select');
  52. var selNew = selAll[selAll.length-1];
  53. if(formChild.nodeName=='SELECT') selNew = formChild;
  54. for(i=0;i<selAll.length;i++) fill_sell(selAll[i], oOpts, collect(selAll[i].form));
  55. }
  56. function collect(frm) // to create an object from all used values
  57. { var selVar = {};
  58. var selAll = frm.getElementsByTagName('select');
  59. for(var k=0;k < selAll.length ;k++)
  60. { if(selAll[k].length>1 && (selAll[k].value in oOpts)) selVar[selAll[k].value]=selAll[k].selectedIndex;
  61. } return selVar;
  62. }
  63. /**********************************************************************/
  64.  
  65. function add(oRow)
  66. { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1));
  67. var inpR = oRow.getElementsByTagName('input');
  68. var inpN = oRow.nextSibling.getElementsByTagName('input');
  69. var selR = oRow.getElementsByTagName('select')[0];
  70. selR.disabled=true;
  71. var selN = oRow.nextSibling.getElementsByTagName('select')[0];
  72. selN.length = 1;
  73. for(i=0;i<inpR.length;i++)
  74. { if(inpR[i].disabled)inpR[i].disabled=false;
  75. if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value=''};
  76. if(inpR[i].value=='add'){inpR[i].value='ed';inpN[i].disabled=true};
  77. } sumus();knockOut(selN);
  78. }
  79.  
  80. function ed(oBut)
  81. { var nextSel = oBut.parentNode.parentNode.nextSibling.firstChild.firstChild;
  82. var trow = oBut.parentNode.parentNode;
  83. var inpR = trow.getElementsByTagName('input');
  84. var selR = trow.getElementsByTagName('select')[0];
  85. var addrow = trow.parentNode.childNodes[trow.parentNode.lastChild.rowIndex-1]
  86. var addeds = d.getElementsByName('added');
  87. for(i=0;i<inpR.length;i++)
  88. { if(oBut.value=='ed' && inpR[i].type=='text'){inpR[i].disabled=false;selR.disabled=false;}
  89. if(oBut.value=='lock' && inpR[i].type=='text'){inpR[i].disabled=true; selR.disabled=true;}
  90. }
  91. if(oBut.value=='ed')
  92. { oBut.value='lock'
  93. for(i=0;i<addeds.length;i++)
  94. { addeds[i].disabled=true;
  95. } oBut.disabled=false;
  96. addrow.childNodes[0].firstChild.disabled=true;
  97. addrow.childNodes[1].firstChild.disabled=true;
  98. addrow.childNodes[2].firstChild.disabled=true;
  99. } else // oBut.value is not 'lock'
  100. { oBut.value='ed'
  101. for(i=0;i<addeds.length;i++)
  102. { addeds[i].disabled=false;
  103. } emptyStr(addeds[i-1].parentNode.parentNode)
  104. addrow.childNodes[0].firstChild.disabled=false;
  105. addrow.childNodes[1].firstChild.disabled=false;
  106. addrow.childNodes[2].firstChild.disabled=false;
  107. } knockOut(nextSel);
  108. //alert(nextSel);
  109. }
  110. function send(oForm)
  111. { var inpF = oForm.getElementsByTagName('input');
  112. for(i=0;i<inpF.length;i++)
  113. { inpF[i].disabled=false;
  114. } oForm.submit();
  115. } function check(strt){ return (/^\d*\.?\d*/.exec(strt)==strt)?strt:check(strt.slice(0,(strt.length-1))) }
  116. function emptyStr(oRow)
  117. { var oInpS =oRow.getElementsByTagName('input');var sum1=0,sum2=0;
  118. oInpS[0].value=check(oInpS[0].value); oInpS[1].value=check(oInpS[1].value);
  119. if( oInpS[0].value && !(oInpS[1].value) || oInpS[1].value && !(oInpS[0].value))
  120. oInpS[2].disabled=false;
  121. else oInpS[2].disabled=true;
  122. sumus();
  123. }
  124. function sumus()
  125. { var sum1=0,sum2=0;
  126. var Col1InpS = d.getElementsByName('row[credit][]');
  127. var Col2InpS = d.getElementsByName('row[debet][]');
  128. for(i=0;i<Col1InpS.length;i++)
  129. { sum1+=1*Col1InpS[i].value;sum2+=1*Col2InpS[i].value;
  130. } d.getElementById('s1').innerHTML=sum1;d.getElementById('s2').innerHTML=sum2;
  131. }
  132. </script>
  133. </HEAD>
  134. <BODY><form method="post" action="./fuj.php">
  135. <table><tbody><tr><td><select name="row[brand][]" onChange="knockOut(this)"><option value="" disabled="true">Choose one</option></td><td><input type="text" name="row[credit][]" onKeyUp=" emptyStr(this.parentNode.parentNode)" onBlur="emptyStr(this.parentNode.parentNode)" ></td><td><input type="text" name="row[debet][]" onKeyUp="this.value=check(this.value); emptyStr(this.parentNode.parentNode)" onBlur="emptyStr(this.parentNode.parentNode)"></td><td><input type="button" name="added" value="add" onClick="(this.value=='add')?add( this.parentNode.parentNode ):ed(this) " disabled="true"></td><td><input type="button" value="del" onClick="var nextSel = this.parentNode.parentNode.nextSibling.firstChild.firstChild; ed(this); this.parentNode.parentNode.parentNode.deleteRow( this.parentNode.parentNode.rowIndex ); sumus(); knockOut(nextSel);" disabled="true"></td></tr><tr><td></td><td id="s1"></td><td id="s2"></td><td></td><td></td></tr></tbody></table>
  136. <br><input type="button" value="send" onClick="send(this.form)">
  137. <script>fill_sell(d.getElementsByTagName('select')[0],oOpts)</script>
  138. </form><br>
  139. <?php print_r($_POST["row"]);print_r($wor);?>
  140. </BODY>
  141. </HTML>
Thanks again Sir...!!! Superb Work..!!!
but have to notice.. the brand u select once does not come for second time..!! i means once u select 'Water'option...it does not
come in second Row..!!
javascript is very confusing
  1. <?
  2. include_once('session.php');
  3. include_once('datainsert.php');
  4. include_once('config2.php');
  5. ?>
  6. <?php
  7. if($row=$_POST['row'])
  8. { foreach($row as $k => $v)
  9. { foreach($v as $kk => $vv)
  10. { $wor[$kk][$k]=$vv;
  11. };
  12. };
  13. } else $wor="";
  14.  
  15. /* $userid = $_SESSION['userid'];
  16.   $sql="SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid";
  17.   $result=mysql_query($sql)or die('Query error:'.''.mysql_errno());
  18.  
  19.   $arrBrand = array();
  20.   while($row=mysql_fetch_array($result)) {
  21.   $arrBrand[$row['ledger_id']] = $row['ledgerName'];
  22.   } */

Sir this is my php code in comment with query...
how can i implement there..in in place of array.....??

Thanks Sir..!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 83
Reputation: nish123 is an unknown quantity at this point 
Solved Threads: 0
nish123's Avatar
nish123 nish123 is offline Offline
Junior Poster in Training

Re: Add/Remove rows from Table

 
0
  #22
Jul 3rd, 2009
and one more thing.. when i send data... the BRAND array shows blank..!! i dont knw why..??
Last edited by nish123; Jul 3rd, 2009 at 3:46 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 49
Reputation: sysel is an unknown quantity at this point 
Solved Threads: 3
sysel sysel is offline Offline
Light Poster

Re: Add/Remove rows from Table

 
0
  #23
Jul 3rd, 2009
I am bac again :-)

-- the brand u select once does not come for second time......
yes, this is the feature maden by the knockOut() function, if not wanted, rewrite the function as this:
function knockOut(formChild) {}
and in the add(oRow) function you must delete the instruction:
selN.length = 1;
-- the empty brand[] array ... as I told, all the 'inputs' must be enabled what I forgot, where I used the attribute disabled, you may have the readonly. In my code add the enabling loop for <SELECT> elements in the send() function:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function send(oForm)
  2. { var inpF = oForm.getElementsByTagName('input');
  3. for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; }
  4. var inpF = oForm.getElementsByTagName('select');
  5. for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; }
  6. oForm.submit();
  7. }

-- the $arrBrand filling code looks correct, I hope, that the keys are unique :-)

With the javascript you can also enable the [add] button on the extended condition that the 'brand' must be selected, too.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 83
Reputation: nish123 is an unknown quantity at this point 
Solved Threads: 0
nish123's Avatar
nish123 nish123 is offline Offline
Junior Poster in Training

Re: Add/Remove rows from Table

 
0
  #24
Jul 3rd, 2009
Originally Posted by sysel View Post
I am bac again :-)

-- the brand u select once does not come for second time......
yes, this is the feature maden by the knockOut() function, if not wanted, rewrite the function as this:
function knockOut(formChild) {}
and in the add(oRow) function you must delete the instruction:
selN.length = 1;
-- the empty brand[] array ... as I told, all the 'inputs' must be enabled what I forgot, where I used the attribute disabled, you may have the readonly. In my code add the enabling loop for <SELECT> elements in the send() function:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function send(oForm)
  2. { var inpF = oForm.getElementsByTagName('input');
  3. for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; }
  4. var inpF = oForm.getElementsByTagName('select');
  5. for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; }
  6. oForm.submit();
  7. }

-- the $arrBrand filling code looks correct, I hope, that the keys are unique :-)

With the javascript you can also enable the [add] button on the extended condition that the 'brand' must be selected, too.
  1. <?
  2. include_once('session.php');
  3. include_once('datainsert.php');
  4. include_once('config2.php');
  5. ?>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html dir="ltr"><head>
  8. <title>Journal Entry</title><meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1">
  9. <link href="default.css" rel="stylesheet" type="text/css">
  10. <script type="text/javascript" src="time.js"></script>
  11. <script type="text/javascript" src="currentdate.js"></script>
  12. <script language="JavaScript" src="calendar_us.js"></script>
  13. <link rel="stylesheet" href="calendar.css">
  14.  
  15. <?php
  16. if($row=$_POST['row'])
  17. { foreach($row as $k => $v)
  18. { foreach($v as $kk => $vv)
  19. { $wor[$kk][$k]=$vv;
  20. };
  21. };
  22. } else $wor="";
  23.  
  24. $userid = $_SESSION['userid'];
  25. $sql="SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid";
  26. $result=mysql_query($sql)or die('Query error:'.''.mysql_errno());
  27.  
  28. $arrBrand = array();
  29. while($row=mysql_fetch_array($result)) {
  30. $arrBrand[$row['ledger_id']] = $row['ledgerName'];
  31. }
  32.  
  33. /*$arrBrand=array(1=>"Electricity"
  34.   ,2=>"Water"
  35.   ,3=>"Gas"
  36.   ,4=>"Appartement Rent"
  37.   ,5=>"School Fee"); */
  38. /** $arrayBrand can be get from a database
  39. $res=mysql_query("SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid");
  40. $i=0;while($cols = mysql_fetch_row($dbResult))
  41. {$line[$i]="'$i':['$i++','".$cols[0]."']";
  42. }
  43. //*/
  44.  
  45. foreach($arrBrand as $kk => $vv){ $line[]="'$kk':['$kk','$vv']";}
  46. $optOut="\n{".implode("\n,",$line)."}";
  47. /*echo '<pre>';print_r($arrBrand);
  48. print_r($line);
  49. print_r($optOut); */
  50. ////oSel.length = 0;
  51. ?>
  52. <script>
  53. var i,d=document;
  54. /*********************************************************************/
  55. var oOpts = <?php print $optOut ?>; // move the set of Options into a JS object!
  56.  
  57. function add_option(what,where) // to define and add one Option
  58. { var nop = d.createElement('option');
  59. nop.innerHTML = what[1]; // nop.text does not accept MSIE
  60. nop.value = what[0];
  61. nop.title = nop.alt = what[0]; // showes the option value as 'bubble'
  62. where.appendChild(nop);
  63. }
  64. function fill_sell(oSel,oSet,oExept) // to clear and fill back the Option set
  65. { if(oExept==undefined)oExept={}; // except used ones
  66. var myVal='';if(oSel.length>1){ myVal=oSel.value; oSel.length = 1; }
  67. for(var l in oSet)
  68. { if( (l==myVal) || !(l in oExept) ) add_option(oSet[l],oSel);
  69. } oSel.value=myVal;
  70. }
  71. function knockOut(formChild) // to trim the each <select> option list
  72. { /*var selOpt=collect(formChild.form);
  73.   var selAll = formChild.form.getElementsByTagName('select');
  74.   var selNew = selAll[selAll.length-1];
  75.   if(formChild.nodeName=='SELECT') selNew = formChild;
  76.   for(i=0;i<selAll.length;i++) fill_sell(selAll[i], oOpts, collect(selAll[i].form)); */
  77. }
  78. function collect(frm) // to create an object from all used values
  79. { var selVar = {};
  80. var selAll = frm.getElementsByTagName('select');
  81. for(var k=0;k < selAll.length ;k++)
  82. { if(selAll[k].length>1 && (selAll[k].value in oOpts)) selVar[selAll[k].value]=selAll[k].selectedIndex;
  83. } return selVar;
  84. }
  85. /**********************************************************************/
  86.  
  87. function add(oRow)
  88. { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1));
  89. var inpR = oRow.getElementsByTagName('input');
  90. var inpN = oRow.nextSibling.getElementsByTagName('input');
  91. var selR = oRow.getElementsByTagName('select')[0];
  92. selR.disabled=true;
  93. var selN = oRow.nextSibling.getElementsByTagName('select')[0];
  94. // selN.length = 1;
  95. for(i=0;i<inpR.length;i++)
  96. { if(inpR[i].disabled)inpR[i].disabled=false;
  97. if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value=''};
  98. if(inpR[i].value=='add'){inpR[i].value='ed';inpN[i].disabled=true};
  99. } sumus();knockOut(selN);
  100. }
  101.  
  102. function ed(oBut)
  103. { var nextSel = oBut.parentNode.parentNode.nextSibling.firstChild.firstChild;
  104. var trow = oBut.parentNode.parentNode;
  105. var inpR = trow.getElementsByTagName('input');
  106. var selR = trow.getElementsByTagName('select')[0];
  107. var addrow = trow.parentNode.childNodes[trow.parentNode.lastChild.rowIndex-1]
  108. var addeds = d.getElementsByName('added');
  109. for(i=0;i<inpR.length;i++)
  110. { if(oBut.value=='ed' && inpR[i].type=='text'){inpR[i].disabled=false;selR.disabled=false;}
  111. if(oBut.value=='lock' && inpR[i].type=='text'){inpR[i].disabled=true; selR.disabled=true;}
  112. }
  113. if(oBut.value=='ed')
  114. { oBut.value='lock'
  115. for(i=0;i<addeds.length;i++)
  116. { addeds[i].disabled=true;
  117. } oBut.disabled=false;
  118. addrow.childNodes[0].firstChild.disabled=true;
  119. addrow.childNodes[1].firstChild.disabled=true;
  120. addrow.childNodes[2].firstChild.disabled=true;
  121. } else // oBut.value is not 'lock'
  122. { oBut.value='ed'
  123. for(i=0;i<addeds.length;i++)
  124. { addeds[i].disabled=false;
  125. } emptyStr(addeds[i-1].parentNode.parentNode)
  126. addrow.childNodes[0].firstChild.disabled=false;
  127. addrow.childNodes[1].firstChild.disabled=false;
  128. addrow.childNodes[2].firstChild.disabled=false;
  129. } knockOut(nextSel);
  130. //alert(nextSel);
  131. }
  132. function send(oForm)
  133. { var inpF = oForm.getElementsByTagName('input');
  134. for(i=0;i<inpF.length;i++)
  135. { inpF[i].disabled=false;
  136. } oForm.submit();
  137. } function check(strt){ return (/^\d*\.?\d*/.exec(strt)==strt)?strt:check(strt.slice(0,(strt.length-1))) }
  138. function emptyStr(oRow)
  139. { var oInpS =oRow.getElementsByTagName('input');var sum1=0,sum2=0;
  140. oInpS[0].value=check(oInpS[0].value); oInpS[1].value=check(oInpS[1].value);
  141. if( oInpS[0].value && !(oInpS[1].value) || oInpS[1].value && !(oInpS[0].value))
  142. oInpS[2].disabled=false;
  143. else oInpS[2].disabled=true;
  144. sumus();
  145. }
  146. function sumus()
  147. { var sum1=0,sum2=0;
  148. var Col1InpS = d.getElementsByName('row[credit][]');
  149. var Col2InpS = d.getElementsByName('row[debet][]');
  150. for(i=0;i<Col1InpS.length;i++)
  151. { sum1+=1*Col1InpS[i].value;sum2+=1*Col2InpS[i].value;
  152. } d.getElementById('s1').innerHTML=sum1;d.getElementById('s2').innerHTML=sum2;
  153. }
  154. </script>
  155. </HEAD>
  156. <table align="center" style="border-collapse: collapse;" id="tblSample" width="95%" bgcolor="#f9f9f9" border="1" bordercolor="#cccccc" cellpadding="3" cellspacing="0" id="testtable">
  157. <tr><td align="center"><select name="row[brand][]" onChange="knockOut(this)"><option value="" disabled="true">Choose one
  158. </option></td>
  159. <td align="center"><input type="text" name="row[credit][]" onKeyUp=" emptyStr(this.parentNode.parentNode)" onBlur="emptyStr(this.parentNode.parentNode)" ></td>
  160. <td align="center"><input type="text" name="row[debet][]" onKeyUp="this.value=check(this.value); emptyStr(this.parentNode.parentNode)" onBlur="emptyStr(this.parentNode.parentNode)"></td>
  161. <td align="center"><input type="button" name="added" value="add" onClick="(this.value=='add')?add( this.parentNode.parentNode ):ed(this) " disabled="true"><input type="button" value="del" onClick="var nextSel = this.parentNode.parentNode.nextSibling.firstChild.firstChild; ed(this); this.parentNode.parentNode.parentNode.deleteRow( this.parentNode.parentNode.rowIndex ); sumus(); knockOut(nextSel);" disabled="true"></td></tr>
  162. <tr>
  163. <td>Total</td>
  164. <td id="s1"></td>
  165. <td id="s2"></td>
  166. <td></td>
  167. </tr></tbody></table>
  168. <br><input type="button" value="send" onClick="send(this.form)">
  169. <script>fill_sell(d.getElementsByTagName('select')[0],oOpts)</script>
  170. </form><br>
  171. <?php echo '<pre>';print_r($_POST["row"]);print_r($wor);?>
  172. </BODY>
  173. </HTML>

Sir i dont knw what is happening... again the code creating problem in Firefox...!!!!

But i will not loose the hope..!!
Last edited by peter_budo; Jul 4th, 2009 at 6:09 am. Reason: Correcting code tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 83
Reputation: nish123 is an unknown quantity at this point 
Solved Threads: 0
nish123's Avatar
nish123 nish123 is offline Offline
Junior Poster in Training

Re: Add/Remove rows from Table

 
0
  #25
Jul 3rd, 2009
Originally Posted by sysel View Post
I am bac again :-)

-- the brand u select once does not come for second time......
yes, this is the feature maden by the knockOut() function, if not wanted, rewrite the function as this:
function knockOut(formChild) {}
and in the add(oRow) function you must delete the instruction:
selN.length = 1;
-- the empty brand[] array ... as I told, all the 'inputs' must be enabled what I forgot, where I used the attribute disabled, you may have the readonly. In my code add the enabling loop for <SELECT> elements in the send() function:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function send(oForm)
  2. { var inpF = oForm.getElementsByTagName('input');
  3. for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; }
  4. var inpF = oForm.getElementsByTagName('select');
  5. for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; }
  6. oForm.submit();
  7. }

-- the $arrBrand filling code looks correct, I hope, that the keys are unique :-)

With the javascript you can also enable the [add] button on the extended condition that the 'brand' must be selected, too.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?
  2. include_once('session.php');
  3. include_once('datainsert.php');
  4. include_once('config2.php');
  5. ?>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html dir="ltr"><head>
  8. <title>Journal Entry</title><meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1">
  9. <link href="default.css" rel="stylesheet" type="text/css">
  10. <script type="text/javascript" src="time.js"></script>
  11. <script type="text/javascript" src="currentdate.js"></script>
  12. <script language="JavaScript" src="calendar_us.js"></script>
  13. <link rel="stylesheet" href="calendar.css">
  14.  
  15. <?php
  16. if($row=$_POST['row'])
  17. { foreach($row as $k => $v)
  18. { foreach($v as $kk => $vv)
  19. { $wor[$kk][$k]=$vv;
  20. };
  21. };
  22. } else $wor="";
  23.  
  24. $userid = $_SESSION['userid'];
  25. $sql="SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid";
  26. $result=mysql_query($sql)or die('Query error:'.''.mysql_errno());
  27.  
  28. $arrBrand = array();
  29. while($row=mysql_fetch_array($result)) {
  30. $arrBrand[$row['ledger_id']] = $row['ledgerName'];
  31. }
  32.  
  33. /*$arrBrand=array(1=>"Electricity"
  34.   ,2=>"Water"
  35.   ,3=>"Gas"
  36.   ,4=>"Appartement Rent"
  37.   ,5=>"School Fee"); */
  38. /** $arrayBrand can be get from a database
  39. $res=mysql_query("SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid");
  40. $i=0;while($cols = mysql_fetch_row($dbResult))
  41. {$line[$i]="'$i':['$i++','".$cols[0]."']";
  42. }
  43. //*/
  44.  
  45. foreach($arrBrand as $kk => $vv){ $line[]="'$kk':['$kk','$vv']";}
  46. $optOut="\n{".implode("\n,",$line)."}";
  47. /*echo '<pre>';print_r($arrBrand);
  48. print_r($line);
  49. print_r($optOut); */
  50. ////oSel.length = 0;
  51. ?>
  52. <script>
  53. var i,d=document;
  54. /*********************************************************************/
  55. var oOpts = <?php print $optOut ?>; // move the set of Options into a JS object!
  56.  
  57. function add_option(what,where) // to define and add one Option
  58. { var nop = d.createElement('option');
  59. nop.innerHTML = what[1]; // nop.text does not accept MSIE
  60. nop.value = what[0];
  61. nop.title = nop.alt = what[0]; // showes the option value as 'bubble'
  62. where.appendChild(nop);
  63. }
  64. function fill_sell(oSel,oSet,oExept) // to clear and fill back the Option set
  65. { if(oExept==undefined)oExept={}; // except used ones
  66. var myVal='';if(oSel.length>1){ myVal=oSel.value; oSel.length = 1; }
  67. for(var l in oSet)
  68. { if( (l==myVal) || !(l in oExept) ) add_option(oSet[l],oSel);
  69. } oSel.value=myVal;
  70. }
  71. function knockOut(formChild) // to trim the each <select> option list
  72. { /*var selOpt=collect(formChild.form);
  73.   var selAll = formChild.form.getElementsByTagName('select');
  74.   var selNew = selAll[selAll.length-1];
  75.   if(formChild.nodeName=='SELECT') selNew = formChild;
  76.   for(i=0;i<selAll.length;i++) fill_sell(selAll[i], oOpts, collect(selAll[i].form)); */
  77. }
  78. function collect(frm) // to create an object from all used values
  79. { var selVar = {};
  80. var selAll = frm.getElementsByTagName('select');
  81. for(var k=0;k < selAll.length ;k++)
  82. { if(selAll[k].length>1 && (selAll[k].value in oOpts)) selVar[selAll[k].value]=selAll[k].selectedIndex;
  83. } return selVar;
  84. }
  85. /**********************************************************************/
  86.  
  87. function add(oRow)
  88. { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1));
  89. var inpR = oRow.getElementsByTagName('input');
  90. var inpN = oRow.nextSibling.getElementsByTagName('input');
  91. var selR = oRow.getElementsByTagName('select')[0];
  92. selR.disabled=true;
  93. var selN = oRow.nextSibling.getElementsByTagName('select')[0];
  94. // selN.length = 1;
  95. for(i=0;i<inpR.length;i++)
  96. { if(inpR[i].disabled)inpR[i].disabled=false;
  97. if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value=''};
  98. if(inpR[i].value=='add'){inpR[i].value='ed';inpN[i].disabled=true};
  99. } sumus();knockOut(selN);
  100. }
  101.  
  102. function ed(oBut)
  103. { var nextSel = oBut.parentNode.parentNode.nextSibling.firstChild.firstChild;
  104. var trow = oBut.parentNode.parentNode;
  105. var inpR = trow.getElementsByTagName('input');
  106. var selR = trow.getElementsByTagName('select')[0];
  107. var addrow = trow.parentNode.childNodes[trow.parentNode.lastChild.rowIndex-1]
  108. var addeds = d.getElementsByName('added');
  109. for(i=0;i<inpR.length;i++)
  110. { if(oBut.value=='ed' && inpR[i].type=='text'){inpR[i].disabled=false;selR.disabled=false;}
  111. if(oBut.value=='lock' && inpR[i].type=='text'){inpR[i].disabled=true; selR.disabled=true;}
  112. }
  113. if(oBut.value=='ed')
  114. { oBut.value='lock'
  115. for(i=0;i<addeds.length;i++)
  116. { addeds[i].disabled=true;
  117. } oBut.disabled=false;
  118. addrow.childNodes[0].firstChild.disabled=true;
  119. addrow.childNodes[1].firstChild.disabled=true;
  120. addrow.childNodes[2].firstChild.disabled=true;
  121. } else // oBut.value is not 'lock'
  122. { oBut.value='ed'
  123. for(i=0;i<addeds.length;i++)
  124. { addeds[i].disabled=false;
  125. } emptyStr(addeds[i-1].parentNode.parentNode)
  126. addrow.childNodes[0].firstChild.disabled=false;
  127. addrow.childNodes[1].firstChild.disabled=false;
  128. addrow.childNodes[2].firstChild.disabled=false;
  129. } knockOut(nextSel);
  130. //alert(nextSel);
  131. }
  132. function send(oForm)
  133. { var inpF = oForm.getElementsByTagName('input');
  134. for(i=0;i<inpF.length;i++)
  135. { inpF[i].disabled=false;
  136. } oForm.submit();
  137. } function check(strt){ return (/^\d*\.?\d*/.exec(strt)==strt)?strt:check(strt.slice(0,(strt.length-1))) }
  138. function emptyStr(oRow)
  139. { var oInpS =oRow.getElementsByTagName('input');var sum1=0,sum2=0;
  140. oInpS[0].value=check(oInpS[0].value); oInpS[1].value=check(oInpS[1].value);
  141. if( oInpS[0].value && !(oInpS[1].value) || oInpS[1].value && !(oInpS[0].value))
  142. oInpS[2].disabled=false;
  143. else oInpS[2].disabled=true;
  144. sumus();
  145. }
  146. function sumus()
  147. { var sum1=0,sum2=0;
  148. var Col1InpS = d.getElementsByName('row[credit][]');
  149. var Col2InpS = d.getElementsByName('row[debet][]');
  150. for(i=0;i<Col1InpS.length;i++)
  151. { sum1+=1*Col1InpS[i].value;sum2+=1*Col2InpS[i].value;
  152. } d.getElementById('s1').innerHTML=sum1;d.getElementById('s2').innerHTML=sum2;
  153. }
  154. </script>
  155. </HEAD>
  156. <table align="center" style="border-collapse: collapse;" id="tblSample" width="95%" bgcolor="#f9f9f9" border="1" bordercolor="#cccccc" cellpadding="3" cellspacing="0" id="testtable">
  157. <tr><td align="center"><select name="row[brand][]" onChange="knockOut(this)"><option value="" disabled="true">Choose one
  158. </option></td>
  159. <td align="center"><input type="text" name="row[credit][]" onKeyUp=" emptyStr(this.parentNode.parentNode)" onBlur="emptyStr(this.parentNode.parentNode)" ></td>
  160. <td align="center"><input type="text" name="row[debet][]" onKeyUp="this.value=check(this.value); emptyStr(this.parentNode.parentNode)" onBlur="emptyStr(this.parentNode.parentNode)"></td>
  161. <td align="center"><input type="button" name="added" value="add" onClick="(this.value=='add')?add( this.parentNode.parentNode ):ed(this) " disabled="true"><input type="button" value="del" onClick="var nextSel = this.parentNode.parentNode.nextSibling.firstChild.firstChild; ed(this); this.parentNode.parentNode.parentNode.deleteRow( this.parentNode.parentNode.rowIndex ); sumus(); knockOut(nextSel);" disabled="true"></td></tr>
  162. <tr>
  163. <td>Total</td>
  164. <td id="s1"></td>
  165. <td id="s2"></td>
  166. <td></td>
  167. </tr></tbody></table>
  168. <br><input type="button" value="send" onClick="send(this.form)">
  169. <script>fill_sell(d.getElementsByTagName('select')[0],oOpts)</script>
  170. </form><br>
  171. <?php echo '<pre>';print_r($_POST["row"]);print_r($wor);?>
  172. </BODY>
  173. </HTML>

Sir i dont knw what is happening... again the code creating problem in Firefox...!!!!

But i will not loose the hope..!!
Last edited by nish123; Jul 3rd, 2009 at 7:29 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 49
Reputation: sysel is an unknown quantity at this point 
Solved Threads: 3
sysel sysel is offline Offline
Light Poster

Re: Add/Remove rows from Table

 
0
  #26
Jul 3rd, 2009
Hi,

I hope your code needs a minor repair only:
- somehow disappeared the <BODY> & <FORM ..> headings
<BODY><form method="post" action="./ThePage.php"> where ./ThePage.php should be overwritten with correct destination page name;
- the send() function was not extended:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function send(oForm)
  2. { var inpF = oForm.getElementsByTagName('input');
  3. for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; }
  4. var inpF = oForm.getElementsByTagName('select');
  5. for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; }
  6. oForm.submit();
  7. }
- a cosmetic cleaning could be:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var selN = oRow.nextSibling.getElementsByTagName('select')[0];
  2. selN.selectedIndex=0;
in add(oRow)

- the <TABLE> ... </TABLE> definitely MUST be unformated in the code -> written as one single row, because, each [formating | invisible] character as spaces, tabs, and end of line can brake the structure of the DOM (Document Object Model) inserting the unwanted #text elements, hence the relative reference of the type: oElement.parentNode.nextSibling.firstChild reffers to the invisible character instead of the next <INPUT> box.

It is highly recommended to use frequently in FireFox the Error console (or whatever it has English name) and the DOM Inspector (available as free FF plugin). Lot of people use the FireBug plugin for direct debugging of the JavaScript code.

The database exploit seems to be well coded I hope it makes no problems.

I must again admit, that the styled document looks much better than the 'technical' skeleton only :-)
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 83
Reputation: nish123 is an unknown quantity at this point 
Solved Threads: 0
nish123's Avatar
nish123 nish123 is offline Offline
Junior Poster in Training

Re: Add/Remove rows from Table

 
0
  #27
Jul 4th, 2009
Originally Posted by sysel View Post
Hi,

I hope your code needs a minor repair only:
- somehow disappeared the <BODY> & <FORM ..> headings
<BODY><form method="post" action="./ThePage.php"> where ./ThePage.php should be overwritten with correct destination page name;
- the send() function was not extended:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function send(oForm)
  2. { var inpF = oForm.getElementsByTagName('input');
  3. for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; }
  4. var inpF = oForm.getElementsByTagName('select');
  5. for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; }
  6. oForm.submit();
  7. }
- a cosmetic cleaning could be:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var selN = oRow.nextSibling.getElementsByTagName('select')[0];
  2. selN.selectedIndex=0;
in add(oRow)

- the <TABLE> ... </TABLE> definitely MUST be unformated in the code -> written as one single row, because, each [formating | invisible] character as spaces, tabs, and end of line can brake the structure of the DOM (Document Object Model) inserting the unwanted #text elements, hence the relative reference of the type: oElement.parentNode.nextSibling.firstChild reffers to the invisible character instead of the next <INPUT> box.

It is highly recommended to use frequently in FireFox the Error console (or whatever it has English name) and the DOM Inspector (available as free FF plugin). Lot of people use the FireBug plugin for direct debugging of the JavaScript code.

The database exploit seems to be well coded I hope it makes no problems.

I must again admit, that the styled document looks much better than the 'technical' skeleton only :-)
Okay Sir.. may be thats why when i tried to insert my Html code in it.. its shows error..in Firefox... and yes i use firebug... its a great tool..
i want that if u didnt select any option from dropdown..u cant add row..!!! where should i made change..!!
even i change the value of add and del button... to Add items and Delete items... function shows error..!!!!

Sir have to notice that... if u fill values and dont add row.. still your values got passed to next page...!! think to solve this instead of onkeyup..i should use Onclick function to update the total... total got update only when user click the add button..and same in case of edit and lock button...!!!

One more important thing i want to ask... Does it effect the Dom structure when i create new table over your's table(ur code)...
or intserting the rows of your's table into another table....??? does functionality got effected by it..????

Sir can u provide some Good tutorials to understand DOM structure more clearly...!!

Thank u..!!
Last edited by nish123; Jul 4th, 2009 at 1:23 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 49
Reputation: sysel is an unknown quantity at this point 
Solved Threads: 3
sysel sysel is offline Offline
Light Poster

Re: Add/Remove rows from Table

 
0
  #28
Jul 4th, 2009
As I am leaving home for some days:
- the total is processed by the sumus() fc. Pick the function call to this fc. out of the fc. emptyStr(oRow), and and do not forget to append it into ed(oBut)
- in fc. emptyStr(oRow), collect the 'select' element in the same way as the 'input' elements are collected, and add the condition oSelS[0].value != "" into the if(...) statement
- the table core (from <tbody> ... </tbody>) can be moved anywhere in the document and styled as is possible with CSS, you must only keep it compact in ought the realtive refferences remain in force
there may be even more copy of this table in the document but you must decide, if you want to submit values from all tables or one only, to include all tabs in one single <FORM> or each tab in its own <FORM>
- while changing the value of the button, you must change the all the apperance of the value use, because some times the code tests the values, the most clever is put in the head of scripts the var addButtValue='Add an Item', edButtValue='Edit this Row', ... etc and then be able to change values globaly

Try to catch the program structure by identifying the modules and drawing the 'flow chart' and then you can experiment w. modifying the modules and changing the relation between them. While making the changes in some function, make a copy and change its name somewhat, and you can quickly see the result with clear way to return back to original state :-)
The code must be yours, I gave you the suggestion only :-) hence I left in my suggestion the disabled attribute even I admit that the use of readonly attr. is better, you are free to change it on your purposes :-)
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 83
Reputation: nish123 is an unknown quantity at this point 
Solved Threads: 0
nish123's Avatar
nish123 nish123 is offline Offline
Junior Poster in Training

Re: Add/Remove rows from Table

 
0
  #29
Jul 4th, 2009
Originally Posted by sysel View Post
As I am leaving home for some days:
- the total is processed by the sumus() fc. Pick the function call to this fc. out of the fc. emptyStr(oRow), and and do not forget to append it into ed(oBut)
- in fc. emptyStr(oRow), collect the 'select' element in the same way as the 'input' elements are collected, and add the condition oSelS[0].value != "" into the if(...) statement
- the table core (from <tbody> ... </tbody>) can be moved anywhere in the document and styled as is possible with CSS, you must only keep it compact in ought the realtive refferences remain in force
there may be even more copy of this table in the document but you must decide, if you want to submit values from all tables or one only, to include all tabs in one single <FORM> or each tab in its own <FORM>
- while changing the value of the button, you must change the all the apperance of the value use, because some times the code tests the values, the most clever is put in the head of scripts the var addButtValue='Add an Item', edButtValue='Edit this Row', ... etc and then be able to change values globaly

Try to catch the program structure by identifying the modules and drawing the 'flow chart' and then you can experiment w. modifying the modules and changing the relation between them. While making the changes in some function, make a copy and change its name somewhat, and you can quickly see the result with clear way to return back to original state :-)
The code must be yours, I gave you the suggestion only :-) hence I left in my suggestion the disabled attribute even I admit that the use of readonly attr. is better, you are free to change it on your purposes :-)
Great Sir.. Code is working perfectly and fine in IE and Firefox..!!!
Earlier i tried to add new row in beginning for column headers.. and thts creating problem.. i think that interrupting the DOM structure..!!
So i create separate table headers in seprate table..!!

I found DOM.. little Complex but really interesting...!!

Now i m trying when user fills value in one textbox,the other textbox got disable...!! instead of add button... how is the Idea..?
and on edit only that textbox enable which contains Value and dropdown...!!!

I wish i can also play with DOM like You..! lolzz
Last edited by nish123; Jul 4th, 2009 at 7:09 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 13
Reputation: sharao is an unknown quantity at this point 
Solved Threads: 0
sharao sharao is offline Offline
Newbie Poster

Re: Add/Remove rows from Table

 
0
  #30
Jul 5th, 2009
hi i also face this problem 1year back bcz i too developed accts package, it was in jsp,javascript iam sending the code plz check

save the below code in .jsp file and run u will get Ans: before that plz go through the code once and follow the comments....all the best

even if u save with .html also it's work but before that have to delete some lines.. if u have any queries ask bcz i know..i face so much prblm with that

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. /* For getting data from db
  2.  
  3. <% ArrayList catgid=new ArrayList();
  4. ArrayList catgname=new ArrayList();
  5. rs=st.executeQuery("select MA_code,MA_name from MA_MAST");
  6. while(rs.next()){
  7. maid.add(rs.getString(1));
  8. maname.add(rs.getString(2));
  9. }
  10. rs=null;
  11.  
  12. %>
  13. */
  14.  
  15. <html>
  16. <head>
  17. <script>
  18.  
  19. ///////////////////////////////ADD ROW/////////////
  20.  
  21. //addrow
  22. function insRow(TDid,TRid)
  23. {
  24. //alert("in ins row");
  25.  
  26. selTD = document.getElementById(TDid);
  27. selTR = document.getElementById(TRid);
  28. intRowSpan = selTD.getAttribute("rowSpan");
  29. intRowIndex = selTR.getAttribute("rowIndex");
  30. intInsPos = intRowSpan + intRowIndex ;
  31. var oTR = document.all.TABLE1.insertRow(intInsPos);
  32.  
  33. var RowId =intInsPos;
  34. //var s=RowId-1;
  35. s=intRowSpan
  36.  
  37. var oC1TD = oTR.insertCell(0);
  38. oC1TD.innerHTML = "<input type=text readonly class=text_box2 size=4 name=slno"+s+" value="+s+">";
  39.  
  40. var oC2TD = oTR.insertCell(1);
  41. oC2TD.innerHTML = "<input type=text readonly class=text_box2 size=4 name=mainac"+s+" value="+s+">";
  42.  
  43. //the below two rows r replace for above 2 rows, if u want to get a/c from db use the below on, before this u have to get data from jsp i will put that in top in comments see that
  44.  
  45. //var oC2TD = oTR.insertCell(1);
  46. //oC2TD.innerHTML = "<select name=lstCatgId"+s+" tabindex=9 onclick=total() onchange=showCatg(this.value,"+s+")><option selected>---Category---</option> <%for(int p=0;p!=catgid.size();p++){%><option value=<%=catgid.get(p)%>><%=catgname.get(p)%></option><%}%></select>";
  47.  
  48. var oC3TD = oTR.insertCell(2);
  49. oC3TD.innerHTML = "<input type=text name=subac"+s+" id=subac"+s+" readonly class=textbox_hide style=text-align:right size=8 value=0>";
  50.  
  51. var oC4TD = oTR.insertCell(3);
  52. oC4TD.innerHTML = "<input type=text class=text_box2 size=8 onkeyup=total() id=billdt"+s+" tabindex=10 name=txtPaidFCT"+s+">";
  53.  
  54. var oC5TD = oTR.insertCell(4);
  55. oC5TD.innerHTML = "<input type=text class=textbox_hide size=11 style=text-align:right value=0 readonly id=prtclrs"+s+" name=prtclrs"+s+">";//value="+sno+"
  56.  
  57. var oC6TD = oTR.insertCell(5);
  58. oC6TD.innerHTML = "<input type=text class=text_box2 size=11 onkeyup=totalBon() tabindex=11 name=txtTotAmt"+s+" >";
  59.  
  60. var oC7TD = oTR.insertCell(6);
  61. oC7TD.innerHTML = "<input type=text class=textbox_hide size=10 readonly style=text-align:right value=0 id=flag"+s+" name=flag"+s+" >";
  62.  
  63. var oC8TD = oTR.insertCell(7);
  64. oC8TD.innerHTML = "<input type=text name=etc1"+s+" />"
  65.  
  66.  
  67. //"<input type=text class=text_box2 name=lstPrgName"+s+" >";
  68.  
  69. var oC9TD = oTR.insertCell(8);
  70. oC9TD.innerHTML = "<input type=text class=text_box2 name=etc2"+s+" onkeyup=sponcerCheck() tabindex=13><input type=button onclick=delRow1("+s+") value=X >";
  71.  
  72. /*var oC10TD = oTR.insertCell(9);
  73. oC10TD.innerHTML = "<input type=hidden readonly class=text_box2 size=5 name=txtCatgId"+s+">";
  74. */
  75.  
  76. document.getElementById("htncount").value = RowId;
  77. document.getElementById("count").value = RowId;
  78. selTD.setAttribute("rowSpan",selTD.getAttribute("rowSpan")+1);
  79. }
  80.  
  81.  
  82.  
  83.  
  84. //////////////////////////////////////////////////
  85. function delRow1(s){
  86. var x=intRowSpan-s;
  87. n=s+1;
  88. for(i=1;i<=x;i++){
  89. var j=n-1;
  90.  
  91. document.getElementById("slno"+j).value=j;
  92. document.getElementById("mainac"+j).value=document.getElementById("mainac"+n).value;
  93. document.getElementById("subac"+j).value=document.getElementById("subac"+n).value;
  94. document.getElementById("billdt"+j).value=document.getElementById("billdt"+n).value;
  95. document.getElementById("prtclrs"+j).value=document.getElementById("prtclrs"+n).value;
  96. document.getElementById("txtTotAmt"+j).value=document.getElementById("txtTotAmt"+n).value;
  97. document.getElementById("flag"+j).value=document.getElementById("flag"+n).value;
  98. document.getElementById("etc1"+j).value=document.getElementById("etc1"+n).value;
  99. document.getElementById("etc2"+j).value=document.getElementById("etc2"+n).value;
  100. n++;
  101. }
  102. document.all.TABLE1.deleteRow(intInsPos);
  103. intInsPos=intInsPos-1;
  104. intRowSpan=intRowSpan-1;
  105. document.form.action=total();
  106. document.form.htncount.value=intInsPos;
  107. document.form.count.value=intInsPos;
  108.  
  109. }
  110.  
  111.  
  112. function AddRow()
  113. {
  114. var rowcount=document.form.count.value
  115. //alert(rowcount)
  116. if(rowcount!=1)
  117. {
  118. //validations here
  119.  
  120. var flg=0
  121. if(flg==0){
  122. document.form.action="javascript:insRow('mondayTD','mondayTR')"
  123. document.form.submit()
  124. }//if(flg
  125. }//if
  126. else{
  127. document.form.action="javascript:insRow('mondayTD','mondayTR')"
  128. document.form.submit()
  129. }
  130. }//addrow
  131.  
  132. function save(){
  133.  
  134. var rowcount=document.form.count.value
  135. //again validations here
  136.  
  137. var temp=intInsPos-1
  138. if(rowcount!=1)
  139. {
  140. var Row=intInsPos-1;
  141.  
  142. /*compare main a/c name for no one is same */
  143. var temp=intInsPos-1
  144. var flg=0
  145. if(temp>=2)
  146. {
  147. //again validation here
  148.  
  149. if(flg==0){
  150. document.form.action="Proposal_RO_insert.jsp"
  151. document.form.submit()
  152. }//if-flg
  153. }//main if
  154. else
  155. {
  156. alert("Plz click on ADDRow Button")
  157. }//else
  158. return true;
  159. }//save()
  160.  
  161.  
  162. </script>
  163. </head>
  164.  
  165. <body>
  166. <form name="form">
  167. <table width="100%" id="TABLE1" cellspacing="1">
  168. <thead>
  169. <tr class="tdbg1">
  170. <td width="1%"></td>
  171. <th width="6%" class="TH1">S.No.</th>
  172. <th width="9%" class="TH1">Head of A/c</th>
  173. <th width="8%" class="TH1">Sub A/c</th>
  174. <th width="9%" class="TH1">Paid Bill Date</th>
  175. <th width="8%" class="TH1">Particulars</th>
  176. <th width="12%" class="TH1">Amount</th>
  177. <th width="10%" class="TH1">Flag</th>
  178. <th width="17%" class="TH1">etc.,</th>
  179. <th width="20%" class="TH1">etc.,</th>
  180. </tr>
  181. </thead>
  182. <tr id="mondayTR" >
  183. <td id="MondayTD"></td>
  184. </tr>
  185. </table>
  186.  
  187. <input type="button" value="Submit" onclick="save()"/>
  188. <input name="hidden" type="hidden" id="htnDcode" runat="server" />
  189. <input type="hidden" runat="server" id="htncount" name="htncount1" />
  190. <input type="hidden" runat="server" id="htncount" name="count" value="1" />
  191. <input type=hidden runat=server id=htnt name="str" >
  192. </form>
  193. </body>
  194.  
  195. </html>
Last edited by sharao; Jul 5th, 2009 at 2:42 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC