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)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML><HEAD> <META http-equiv="content-type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <TITLE>add/ed/del row</TITLE><?php ?> <?php /*comments*/?> <?php if($row=$_POST['row']) { foreach($row as $k => $v) { foreach($v as $kk => $vv) { $wor[$kk][$k]=$vv; }; }; } else $wor=""; $arrBrand=array(1=>"Electricity" ,2=>"Water" ,3=>"Gas" ,4=>"Appartement Rent" ,5=>"School Fee"); /** $arrayBrand can be get from a database $res=mysql_query("SELECT distinct brand FROM table"); $i=0;while($cols = mysql_fetch_row($dbResult)) {$line[$i]="'$i':['$i++','".$cols[0]."']"; } //*/ foreach($arrBrand as $kk => $vv){ $line[]="'$kk':['$kk','$vv']";} $optOut="\n{".implode("\n,",$line)."}"; ////oSel.length = 0; ?> <script> var i,d=document; /*********************************************************************/ var oOpts = <?php print $optOut ?>; // move the set of Options into a JS object! function add_option(what,where) // to define and add one Option { var nop = d.createElement('option'); nop.innerHTML = what[1]; // nop.text does not accept MSIE nop.value = what[0]; nop.title = nop.alt = what[0]; // showes the option value as 'bubble' where.appendChild(nop); } function fill_sell(oSel,oSet,oExept) // to clear and fill back the Option set { if(oExept==undefined)oExept={}; // except used ones var myVal='';if(oSel.length>1){ myVal=oSel.value; oSel.length = 1; } for(var l in oSet) { if( (l==myVal) || !(l in oExept) ) add_option(oSet[l],oSel); } oSel.value=myVal; } function knockOut(formChild) // to trim the each <select> option list { var selOpt=collect(formChild.form); var selAll = formChild.form.getElementsByTagName('select'); var selNew = selAll[selAll.length-1]; if(formChild.nodeName=='SELECT') selNew = formChild; for(i=0;i<selAll.length;i++) fill_sell(selAll[i], oOpts, collect(selAll[i].form)); } function collect(frm) // to create an object from all used values { var selVar = {}; var selAll = frm.getElementsByTagName('select'); for(var k=0;k < selAll.length ;k++) { if(selAll[k].length>1 && (selAll[k].value in oOpts)) selVar[selAll[k].value]=selAll[k].selectedIndex; } return selVar; } /**********************************************************************/ function add(oRow) { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1)); var inpR = oRow.getElementsByTagName('input'); var inpN = oRow.nextSibling.getElementsByTagName('input'); var selR = oRow.getElementsByTagName('select')[0]; selR.disabled=true; var selN = oRow.nextSibling.getElementsByTagName('select')[0]; selN.length = 1; for(i=0;i<inpR.length;i++) { if(inpR[i].disabled)inpR[i].disabled=false; if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value=''}; if(inpR[i].value=='add'){inpR[i].value='ed';inpN[i].disabled=true}; } sumus();knockOut(selN); } function ed(oBut) { var nextSel = oBut.parentNode.parentNode.nextSibling.firstChild.firstChild; var trow = oBut.parentNode.parentNode; var inpR = trow.getElementsByTagName('input'); var selR = trow.getElementsByTagName('select')[0]; var addrow = trow.parentNode.childNodes[trow.parentNode.lastChild.rowIndex-1] var addeds = d.getElementsByName('added'); for(i=0;i<inpR.length;i++) { if(oBut.value=='ed' && inpR[i].type=='text'){inpR[i].disabled=false;selR.disabled=false;} if(oBut.value=='lock' && inpR[i].type=='text'){inpR[i].disabled=true; selR.disabled=true;} } if(oBut.value=='ed') { oBut.value='lock' for(i=0;i<addeds.length;i++) { addeds[i].disabled=true; } oBut.disabled=false; addrow.childNodes[0].firstChild.disabled=true; addrow.childNodes[1].firstChild.disabled=true; addrow.childNodes[2].firstChild.disabled=true; } else // oBut.value is not 'lock' { oBut.value='ed' for(i=0;i<addeds.length;i++) { addeds[i].disabled=false; } emptyStr(addeds[i-1].parentNode.parentNode) addrow.childNodes[0].firstChild.disabled=false; addrow.childNodes[1].firstChild.disabled=false; addrow.childNodes[2].firstChild.disabled=false; } knockOut(nextSel); //alert(nextSel); } function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; } oForm.submit(); } function check(strt){ return (/^\d*\.?\d*/.exec(strt)==strt)?strt:check(strt.slice(0,(strt.length-1))) } function emptyStr(oRow) { var oInpS =oRow.getElementsByTagName('input');var sum1=0,sum2=0; oInpS[0].value=check(oInpS[0].value); oInpS[1].value=check(oInpS[1].value); if( oInpS[0].value && !(oInpS[1].value) || oInpS[1].value && !(oInpS[0].value)) oInpS[2].disabled=false; else oInpS[2].disabled=true; sumus(); } function sumus() { var sum1=0,sum2=0; var Col1InpS = d.getElementsByName('row[credit][]'); var Col2InpS = d.getElementsByName('row[debet][]'); for(i=0;i<Col1InpS.length;i++) { sum1+=1*Col1InpS[i].value;sum2+=1*Col2InpS[i].value; } d.getElementById('s1').innerHTML=sum1;d.getElementById('s2').innerHTML=sum2; } </script> </HEAD> <BODY><form method="post" action="./fuj.php"> <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> <br><input type="button" value="send" onClick="send(this.form)"> <script>fill_sell(d.getElementsByTagName('select')[0],oOpts)</script> </form><br> <?php print_r($_POST["row"]);print_r($wor);?> </BODY> </HTML>

<? include_once('session.php'); include_once('datainsert.php'); include_once('config2.php'); ?> <?php if($row=$_POST['row']) { foreach($row as $k => $v) { foreach($v as $kk => $vv) { $wor[$kk][$k]=$vv; }; }; } else $wor=""; /* $userid = $_SESSION['userid']; $sql="SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid"; $result=mysql_query($sql)or die('Query error:'.''.mysql_errno()); $arrBrand = array(); while($row=mysql_fetch_array($result)) { $arrBrand[$row['ledger_id']] = $row['ledgerName']; } */
function knockOut(formChild) {} selN.length = 1;
function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; } var inpF = oForm.getElementsByTagName('select'); for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; } oForm.submit(); }
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)
function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; } var inpF = oForm.getElementsByTagName('select'); for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; } oForm.submit(); }
-- 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.
<? include_once('session.php'); include_once('datainsert.php'); include_once('config2.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html dir="ltr"><head> <title>Journal Entry</title><meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1"> <link href="default.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="time.js"></script> <script type="text/javascript" src="currentdate.js"></script> <script language="JavaScript" src="calendar_us.js"></script> <link rel="stylesheet" href="calendar.css"> <?php if($row=$_POST['row']) { foreach($row as $k => $v) { foreach($v as $kk => $vv) { $wor[$kk][$k]=$vv; }; }; } else $wor=""; $userid = $_SESSION['userid']; $sql="SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid"; $result=mysql_query($sql)or die('Query error:'.''.mysql_errno()); $arrBrand = array(); while($row=mysql_fetch_array($result)) { $arrBrand[$row['ledger_id']] = $row['ledgerName']; } /*$arrBrand=array(1=>"Electricity" ,2=>"Water" ,3=>"Gas" ,4=>"Appartement Rent" ,5=>"School Fee"); */ /** $arrayBrand can be get from a database $res=mysql_query("SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid"); $i=0;while($cols = mysql_fetch_row($dbResult)) {$line[$i]="'$i':['$i++','".$cols[0]."']"; } //*/ foreach($arrBrand as $kk => $vv){ $line[]="'$kk':['$kk','$vv']";} $optOut="\n{".implode("\n,",$line)."}"; /*echo '<pre>';print_r($arrBrand); print_r($line); print_r($optOut); */ ////oSel.length = 0; ?> <script> var i,d=document; /*********************************************************************/ var oOpts = <?php print $optOut ?>; // move the set of Options into a JS object! function add_option(what,where) // to define and add one Option { var nop = d.createElement('option'); nop.innerHTML = what[1]; // nop.text does not accept MSIE nop.value = what[0]; nop.title = nop.alt = what[0]; // showes the option value as 'bubble' where.appendChild(nop); } function fill_sell(oSel,oSet,oExept) // to clear and fill back the Option set { if(oExept==undefined)oExept={}; // except used ones var myVal='';if(oSel.length>1){ myVal=oSel.value; oSel.length = 1; } for(var l in oSet) { if( (l==myVal) || !(l in oExept) ) add_option(oSet[l],oSel); } oSel.value=myVal; } function knockOut(formChild) // to trim the each <select> option list { /*var selOpt=collect(formChild.form); var selAll = formChild.form.getElementsByTagName('select'); var selNew = selAll[selAll.length-1]; if(formChild.nodeName=='SELECT') selNew = formChild; for(i=0;i<selAll.length;i++) fill_sell(selAll[i], oOpts, collect(selAll[i].form)); */ } function collect(frm) // to create an object from all used values { var selVar = {}; var selAll = frm.getElementsByTagName('select'); for(var k=0;k < selAll.length ;k++) { if(selAll[k].length>1 && (selAll[k].value in oOpts)) selVar[selAll[k].value]=selAll[k].selectedIndex; } return selVar; } /**********************************************************************/ function add(oRow) { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1)); var inpR = oRow.getElementsByTagName('input'); var inpN = oRow.nextSibling.getElementsByTagName('input'); var selR = oRow.getElementsByTagName('select')[0]; selR.disabled=true; var selN = oRow.nextSibling.getElementsByTagName('select')[0]; // selN.length = 1; for(i=0;i<inpR.length;i++) { if(inpR[i].disabled)inpR[i].disabled=false; if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value=''}; if(inpR[i].value=='add'){inpR[i].value='ed';inpN[i].disabled=true}; } sumus();knockOut(selN); } function ed(oBut) { var nextSel = oBut.parentNode.parentNode.nextSibling.firstChild.firstChild; var trow = oBut.parentNode.parentNode; var inpR = trow.getElementsByTagName('input'); var selR = trow.getElementsByTagName('select')[0]; var addrow = trow.parentNode.childNodes[trow.parentNode.lastChild.rowIndex-1] var addeds = d.getElementsByName('added'); for(i=0;i<inpR.length;i++) { if(oBut.value=='ed' && inpR[i].type=='text'){inpR[i].disabled=false;selR.disabled=false;} if(oBut.value=='lock' && inpR[i].type=='text'){inpR[i].disabled=true; selR.disabled=true;} } if(oBut.value=='ed') { oBut.value='lock' for(i=0;i<addeds.length;i++) { addeds[i].disabled=true; } oBut.disabled=false; addrow.childNodes[0].firstChild.disabled=true; addrow.childNodes[1].firstChild.disabled=true; addrow.childNodes[2].firstChild.disabled=true; } else // oBut.value is not 'lock' { oBut.value='ed' for(i=0;i<addeds.length;i++) { addeds[i].disabled=false; } emptyStr(addeds[i-1].parentNode.parentNode) addrow.childNodes[0].firstChild.disabled=false; addrow.childNodes[1].firstChild.disabled=false; addrow.childNodes[2].firstChild.disabled=false; } knockOut(nextSel); //alert(nextSel); } function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; } oForm.submit(); } function check(strt){ return (/^\d*\.?\d*/.exec(strt)==strt)?strt:check(strt.slice(0,(strt.length-1))) } function emptyStr(oRow) { var oInpS =oRow.getElementsByTagName('input');var sum1=0,sum2=0; oInpS[0].value=check(oInpS[0].value); oInpS[1].value=check(oInpS[1].value); if( oInpS[0].value && !(oInpS[1].value) || oInpS[1].value && !(oInpS[0].value)) oInpS[2].disabled=false; else oInpS[2].disabled=true; sumus(); } function sumus() { var sum1=0,sum2=0; var Col1InpS = d.getElementsByName('row[credit][]'); var Col2InpS = d.getElementsByName('row[debet][]'); for(i=0;i<Col1InpS.length;i++) { sum1+=1*Col1InpS[i].value;sum2+=1*Col2InpS[i].value; } d.getElementById('s1').innerHTML=sum1;d.getElementById('s2').innerHTML=sum2; } </script> </HEAD> <table align="center" style="border-collapse: collapse;" id="tblSample" width="95%" bgcolor="#f9f9f9" border="1" bordercolor="#cccccc" cellpadding="3" cellspacing="0" id="testtable"> <tr><td align="center"><select name="row[brand][]" onChange="knockOut(this)"><option value="" disabled="true">Choose one </option></td> <td align="center"><input type="text" name="row[credit][]" onKeyUp=" emptyStr(this.parentNode.parentNode)" onBlur="emptyStr(this.parentNode.parentNode)" ></td> <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> <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> <tr> <td>Total</td> <td id="s1"></td> <td id="s2"></td> <td></td> </tr></tbody></table> <br><input type="button" value="send" onClick="send(this.form)"> <script>fill_sell(d.getElementsByTagName('select')[0],oOpts)</script> </form><br> <?php echo '<pre>';print_r($_POST["row"]);print_r($wor);?> </BODY> </HTML>


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)
function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; } var inpF = oForm.getElementsByTagName('select'); for(i=0;i<inpF.length;i++){ inpF[i].disabled=false; } oForm.submit(); }
-- 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.
<? include_once('session.php'); include_once('datainsert.php'); include_once('config2.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html dir="ltr"><head> <title>Journal Entry</title><meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1"> <link href="default.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="time.js"></script> <script type="text/javascript" src="currentdate.js"></script> <script language="JavaScript" src="calendar_us.js"></script> <link rel="stylesheet" href="calendar.css"> <?php if($row=$_POST['row']) { foreach($row as $k => $v) { foreach($v as $kk => $vv) { $wor[$kk][$k]=$vv; }; }; } else $wor=""; $userid = $_SESSION['userid']; $sql="SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid"; $result=mysql_query($sql)or die('Query error:'.''.mysql_errno()); $arrBrand = array(); while($row=mysql_fetch_array($result)) { $arrBrand[$row['ledger_id']] = $row['ledgerName']; } /*$arrBrand=array(1=>"Electricity" ,2=>"Water" ,3=>"Gas" ,4=>"Appartement Rent" ,5=>"School Fee"); */ /** $arrayBrand can be get from a database $res=mysql_query("SELECT * from 0_ledger where group_id not in(1,7) and user_id = $userid"); $i=0;while($cols = mysql_fetch_row($dbResult)) {$line[$i]="'$i':['$i++','".$cols[0]."']"; } //*/ foreach($arrBrand as $kk => $vv){ $line[]="'$kk':['$kk','$vv']";} $optOut="\n{".implode("\n,",$line)."}"; /*echo '<pre>';print_r($arrBrand); print_r($line); print_r($optOut); */ ////oSel.length = 0; ?> <script> var i,d=document; /*********************************************************************/ var oOpts = <?php print $optOut ?>; // move the set of Options into a JS object! function add_option(what,where) // to define and add one Option { var nop = d.createElement('option'); nop.innerHTML = what[1]; // nop.text does not accept MSIE nop.value = what[0]; nop.title = nop.alt = what[0]; // showes the option value as 'bubble' where.appendChild(nop); } function fill_sell(oSel,oSet,oExept) // to clear and fill back the Option set { if(oExept==undefined)oExept={}; // except used ones var myVal='';if(oSel.length>1){ myVal=oSel.value; oSel.length = 1; } for(var l in oSet) { if( (l==myVal) || !(l in oExept) ) add_option(oSet[l],oSel); } oSel.value=myVal; } function knockOut(formChild) // to trim the each <select> option list { /*var selOpt=collect(formChild.form); var selAll = formChild.form.getElementsByTagName('select'); var selNew = selAll[selAll.length-1]; if(formChild.nodeName=='SELECT') selNew = formChild; for(i=0;i<selAll.length;i++) fill_sell(selAll[i], oOpts, collect(selAll[i].form)); */ } function collect(frm) // to create an object from all used values { var selVar = {}; var selAll = frm.getElementsByTagName('select'); for(var k=0;k < selAll.length ;k++) { if(selAll[k].length>1 && (selAll[k].value in oOpts)) selVar[selAll[k].value]=selAll[k].selectedIndex; } return selVar; } /**********************************************************************/ function add(oRow) { oRow.parentNode.replaceChild(oRow.cloneNode(true ),oRow.parentNode.insertRow(oRow.rowIndex+1)); var inpR = oRow.getElementsByTagName('input'); var inpN = oRow.nextSibling.getElementsByTagName('input'); var selR = oRow.getElementsByTagName('select')[0]; selR.disabled=true; var selN = oRow.nextSibling.getElementsByTagName('select')[0]; // selN.length = 1; for(i=0;i<inpR.length;i++) { if(inpR[i].disabled)inpR[i].disabled=false; if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value=''}; if(inpR[i].value=='add'){inpR[i].value='ed';inpN[i].disabled=true}; } sumus();knockOut(selN); } function ed(oBut) { var nextSel = oBut.parentNode.parentNode.nextSibling.firstChild.firstChild; var trow = oBut.parentNode.parentNode; var inpR = trow.getElementsByTagName('input'); var selR = trow.getElementsByTagName('select')[0]; var addrow = trow.parentNode.childNodes[trow.parentNode.lastChild.rowIndex-1] var addeds = d.getElementsByName('added'); for(i=0;i<inpR.length;i++) { if(oBut.value=='ed' && inpR[i].type=='text'){inpR[i].disabled=false;selR.disabled=false;} if(oBut.value=='lock' && inpR[i].type=='text'){inpR[i].disabled=true; selR.disabled=true;} } if(oBut.value=='ed') { oBut.value='lock' for(i=0;i<addeds.length;i++) { addeds[i].disabled=true; } oBut.disabled=false; addrow.childNodes[0].firstChild.disabled=true; addrow.childNodes[1].firstChild.disabled=true; addrow.childNodes[2].firstChild.disabled=true; } else // oBut.value is not 'lock' { oBut.value='ed' for(i=0;i<addeds.length;i++) { addeds[i].disabled=false; } emptyStr(addeds[i-1].parentNode.parentNode) addrow.childNodes[0].firstChild.disabled=false; addrow.childNodes[1].firstChild.disabled=false; addrow.childNodes[2].firstChild.disabled=false; } knockOut(nextSel); //alert(nextSel); } function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; } oForm.submit(); } function check(strt){ return (/^\d*\.?\d*/.exec(strt)==strt)?strt:check(strt.slice(0,(strt.length-1))) } function emptyStr(oRow) { var oInpS =oRow.getElementsByTagName('input');var sum1=0,sum2=0; oInpS[0].value=check(oInpS[0].value); oInpS[1].value=check(oInpS[1].value); if( oInpS[0].value && !(oInpS[1].value) || oInpS[1].value && !(oInpS[0].value)) oInpS[2].disabled=false; else oInpS[2].disabled=true; sumus(); } function sumus() { var sum1=0,sum2=0; var Col1InpS = d.getElementsByName('row[credit][]'); var Col2InpS = d.getElementsByName('row[debet][]'); for(i=0;i<Col1InpS.length;i++) { sum1+=1*Col1InpS[i].value;sum2+=1*Col2InpS[i].value; } d.getElementById('s1').innerHTML=sum1;d.getElementById('s2').innerHTML=sum2; } </script> </HEAD> <table align="center" style="border-collapse: collapse;" id="tblSample" width="95%" bgcolor="#f9f9f9" border="1" bordercolor="#cccccc" cellpadding="3" cellspacing="0" id="testtable"> <tr><td align="center"><select name="row[brand][]" onChange="knockOut(this)"><option value="" disabled="true">Choose one </option></td> <td align="center"><input type="text" name="row[credit][]" onKeyUp=" emptyStr(this.parentNode.parentNode)" onBlur="emptyStr(this.parentNode.parentNode)" ></td> <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> <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> <tr> <td>Total</td> <td id="s1"></td> <td id="s2"></td> <td></td> </tr></tbody></table> <br><input type="button" value="send" onClick="send(this.form)"> <script>fill_sell(d.getElementsByTagName('select')[0],oOpts)</script> </form><br> <?php echo '<pre>';print_r($_POST["row"]);print_r($wor);?> </BODY> </HTML>


<BODY><form method="post" action="./ThePage.php"> where ./ThePage.php should be overwritten with correct destination page name;
function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; } var inpF = oForm.getElementsByTagName('select'); for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; } oForm.submit(); }
var selN = oRow.nextSibling.getElementsByTagName('select')[0]; selN.selectedIndex=0;
<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.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:- a cosmetic cleaning could be:JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function send(oForm) { var inpF = oForm.getElementsByTagName('input'); for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; } var inpF = oForm.getElementsByTagName('select'); for(i=0;i<inpF.length;i++) { inpF[i].disabled=false; } oForm.submit(); }in add(oRow)JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var selN = oRow.nextSibling.getElementsByTagName('select')[0]; selN.selectedIndex=0;
- 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.firstChildreffers 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 :-)

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 :-)
/* For getting data from db <% ArrayList catgid=new ArrayList(); ArrayList catgname=new ArrayList(); rs=st.executeQuery("select MA_code,MA_name from MA_MAST"); while(rs.next()){ maid.add(rs.getString(1)); maname.add(rs.getString(2)); } rs=null; %> */ <html> <head> <script> ///////////////////////////////ADD ROW///////////// //addrow function insRow(TDid,TRid) { //alert("in ins row"); selTD = document.getElementById(TDid); selTR = document.getElementById(TRid); intRowSpan = selTD.getAttribute("rowSpan"); intRowIndex = selTR.getAttribute("rowIndex"); intInsPos = intRowSpan + intRowIndex ; var oTR = document.all.TABLE1.insertRow(intInsPos); var RowId =intInsPos; //var s=RowId-1; s=intRowSpan var oC1TD = oTR.insertCell(0); oC1TD.innerHTML = "<input type=text readonly class=text_box2 size=4 name=slno"+s+" value="+s+">"; var oC2TD = oTR.insertCell(1); oC2TD.innerHTML = "<input type=text readonly class=text_box2 size=4 name=mainac"+s+" value="+s+">"; //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 //var oC2TD = oTR.insertCell(1); //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>"; var oC3TD = oTR.insertCell(2); oC3TD.innerHTML = "<input type=text name=subac"+s+" id=subac"+s+" readonly class=textbox_hide style=text-align:right size=8 value=0>"; var oC4TD = oTR.insertCell(3); oC4TD.innerHTML = "<input type=text class=text_box2 size=8 onkeyup=total() id=billdt"+s+" tabindex=10 name=txtPaidFCT"+s+">"; var oC5TD = oTR.insertCell(4); 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+" var oC6TD = oTR.insertCell(5); oC6TD.innerHTML = "<input type=text class=text_box2 size=11 onkeyup=totalBon() tabindex=11 name=txtTotAmt"+s+" >"; var oC7TD = oTR.insertCell(6); oC7TD.innerHTML = "<input type=text class=textbox_hide size=10 readonly style=text-align:right value=0 id=flag"+s+" name=flag"+s+" >"; var oC8TD = oTR.insertCell(7); oC8TD.innerHTML = "<input type=text name=etc1"+s+" />" //"<input type=text class=text_box2 name=lstPrgName"+s+" >"; var oC9TD = oTR.insertCell(8); oC9TD.innerHTML = "<input type=text class=text_box2 name=etc2"+s+" onkeyup=sponcerCheck() tabindex=13><input type=button onclick=delRow1("+s+") value=X >"; /*var oC10TD = oTR.insertCell(9); oC10TD.innerHTML = "<input type=hidden readonly class=text_box2 size=5 name=txtCatgId"+s+">"; */ document.getElementById("htncount").value = RowId; document.getElementById("count").value = RowId; selTD.setAttribute("rowSpan",selTD.getAttribute("rowSpan")+1); } ////////////////////////////////////////////////// function delRow1(s){ var x=intRowSpan-s; n=s+1; for(i=1;i<=x;i++){ var j=n-1; document.getElementById("slno"+j).value=j; document.getElementById("mainac"+j).value=document.getElementById("mainac"+n).value; document.getElementById("subac"+j).value=document.getElementById("subac"+n).value; document.getElementById("billdt"+j).value=document.getElementById("billdt"+n).value; document.getElementById("prtclrs"+j).value=document.getElementById("prtclrs"+n).value; document.getElementById("txtTotAmt"+j).value=document.getElementById("txtTotAmt"+n).value; document.getElementById("flag"+j).value=document.getElementById("flag"+n).value; document.getElementById("etc1"+j).value=document.getElementById("etc1"+n).value; document.getElementById("etc2"+j).value=document.getElementById("etc2"+n).value; n++; } document.all.TABLE1.deleteRow(intInsPos); intInsPos=intInsPos-1; intRowSpan=intRowSpan-1; document.form.action=total(); document.form.htncount.value=intInsPos; document.form.count.value=intInsPos; } function AddRow() { var rowcount=document.form.count.value //alert(rowcount) if(rowcount!=1) { //validations here var flg=0 if(flg==0){ document.form.action="javascript:insRow('mondayTD','mondayTR')" document.form.submit() }//if(flg }//if else{ document.form.action="javascript:insRow('mondayTD','mondayTR')" document.form.submit() } }//addrow function save(){ var rowcount=document.form.count.value //again validations here var temp=intInsPos-1 if(rowcount!=1) { var Row=intInsPos-1; /*compare main a/c name for no one is same */ var temp=intInsPos-1 var flg=0 if(temp>=2) { //again validation here if(flg==0){ document.form.action="Proposal_RO_insert.jsp" document.form.submit() }//if-flg }//main if else { alert("Plz click on ADDRow Button") }//else return true; }//save() </script> </head> <body> <form name="form"> <table width="100%" id="TABLE1" cellspacing="1"> <thead> <tr class="tdbg1"> <td width="1%"></td> <th width="6%" class="TH1">S.No.</th> <th width="9%" class="TH1">Head of A/c</th> <th width="8%" class="TH1">Sub A/c</th> <th width="9%" class="TH1">Paid Bill Date</th> <th width="8%" class="TH1">Particulars</th> <th width="12%" class="TH1">Amount</th> <th width="10%" class="TH1">Flag</th> <th width="17%" class="TH1">etc.,</th> <th width="20%" class="TH1">etc.,</th> </tr> </thead> <tr id="mondayTR" > <td id="MondayTD"></td> </tr> </table> <input type="button" value="Submit" onclick="save()"/> <input name="hidden" type="hidden" id="htnDcode" runat="server" /> <input type="hidden" runat="server" id="htncount" name="htncount1" /> <input type="hidden" runat="server" id="htncount" name="count" value="1" /> <input type=hidden runat=server id=htnt name="str" > </form> </body> </html>
| DaniWeb Message | |
| Cancel Changes | |