abhit_kumar
03-08-2005, 11:03 PM
hi..KOR..once again i want some modification in ur script(which is given by u)..this modification will be final this time.so plz me help me regarding that...my problem is as follow:-
1)
i want to do that when debit field is having value more than 0 values then automaticallt credit field will be 0 and when credit field is 0 then debit field will be not 0.
2)
The narration field values should be automatically gone into the Description1 field value.
3)
my most priority work is that if the total debit values and total credit values is not equal then at the time of click the submit button, it displays error that total debit values and total credit values should be equal.
4)
one more problem occuring in the rows.....when i add lots of rows by clicking add button, and when i click submit button it reach to the next page, but when i used back button then i found that there is only one row, i want that when i used back button from forwarded page, it should display all the rows.(but it display only one row).plz solve this.....
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function addR(){
var oTab = document.getElementById('tab');// the table element
var oRows = oTab.getElementsByTagName('tr');// the rows collection
var root = oRows[1].parentNode;//the root for the future append
var newRow = oRows[1].cloneNode(true);//clone the second row with the entire content
var oFields = oTab.getElementsByTagName('input')//the text field collection
for (var i=0;i<oFields.length;i++){
if(oFields[i].getAttribute('value').length<1){
alert('Please, fill in all the text fields!');//alerts
oFields[i].focus();//focuses the empty field
return false//stops if one of the text fields is not filled
}
}
var newFields = newRow.getElementsByTagName('input');//the fields in the cloned row collection
for(var i=0;i<newFields.length;i++){
newFields[i].setAttribute('name',newFields[i].getAttribute('name')+'_'+(oRows.length-1));//sets the new incremented names
newFields[i].setAttribute('value','');//clears the values
}
var newSel = newRow.getElementsByTagName('select');//the select elements in the cloned row collection
for(var i=0;i<newSel.length;i++){
newSel[i].setAttribute('name',newSel[i].getAttribute('name')+'_'+(oRows.length-1));//sets the new incremented selects' names
newSel[i].setAttribute('value','');//clears the selects' values
}
root.appendChild(newRow);//appends the new row
root.insertBefore(newRow,document.getElementById('tot'));//appends the new row
}
function addT(n,f){
var re = /^[0-9]*$/;
var vTot='';
var oTab = document.getElementById('tab');// the table element
var oRows = oTab.getElementsByTagName('tr');// the rows collection
var cIndex= f.parentNode.cellIndex;//the index of the cell in row
for(var i=1;i<oRows.length-1;i++){
vTot = vTot*1+oRows[i].getElementsByTagName('input')[cIndex].getAttribute('value')*1;//calculates the total
}
document.forms[1].elements[n].value = vTot//assigns the total
}
</script>
</head>
<body>
<form name="payment_voucher" action="payment_save.jsp" method="post">
<fieldset >
<label> Narration:<input type="text" name="narration" size="60"></label><br>
</fieldset>
<tr>
<TD COLSPAN=6><center><h1><b>BANK PAYMENT INFORMATION</b></h1></center></TD>
</TR>
<table id="tab" width="600" border="3" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th>A/C Cd.</th>
<th>Description</th>
<th>S.L Code</th>
<th>Description1</th>
<th>Debit</th>
<th>Credit</th>
</tr>
<tr>
<td><input type="text" name="Ac.code" size="5" maxlength="5"></td>
<td> <input type="text" name="description" size="30"></td>
<td><input type="text" name="slcode" size="10" ></td>
<td> <input type="text" name="description1" size="30"></td>
<td><input type="text" name="debit" size="12" onkeyup="addT('tdebit',this)"></td>
<td> <input type="text" name="credit" size="12" onkeyup="addT('tcredit',this)"></td>
<tr id="tot">
<td>  </td>
<td>  </td>
<td> </td>
<td><center> TOTAL</center></td>
<td><input type="text" name="tdebit" size="12" > </td>
<td><input type="text" name="tcredit" size="12" > </td>
</tr>
</tbody>
</table>
<br>
<input type="submit" value="Submit" >
<input type="button" value="ADD" onclick="return addR()">
</form>
</body>
</html>
1)
i want to do that when debit field is having value more than 0 values then automaticallt credit field will be 0 and when credit field is 0 then debit field will be not 0.
2)
The narration field values should be automatically gone into the Description1 field value.
3)
my most priority work is that if the total debit values and total credit values is not equal then at the time of click the submit button, it displays error that total debit values and total credit values should be equal.
4)
one more problem occuring in the rows.....when i add lots of rows by clicking add button, and when i click submit button it reach to the next page, but when i used back button then i found that there is only one row, i want that when i used back button from forwarded page, it should display all the rows.(but it display only one row).plz solve this.....
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function addR(){
var oTab = document.getElementById('tab');// the table element
var oRows = oTab.getElementsByTagName('tr');// the rows collection
var root = oRows[1].parentNode;//the root for the future append
var newRow = oRows[1].cloneNode(true);//clone the second row with the entire content
var oFields = oTab.getElementsByTagName('input')//the text field collection
for (var i=0;i<oFields.length;i++){
if(oFields[i].getAttribute('value').length<1){
alert('Please, fill in all the text fields!');//alerts
oFields[i].focus();//focuses the empty field
return false//stops if one of the text fields is not filled
}
}
var newFields = newRow.getElementsByTagName('input');//the fields in the cloned row collection
for(var i=0;i<newFields.length;i++){
newFields[i].setAttribute('name',newFields[i].getAttribute('name')+'_'+(oRows.length-1));//sets the new incremented names
newFields[i].setAttribute('value','');//clears the values
}
var newSel = newRow.getElementsByTagName('select');//the select elements in the cloned row collection
for(var i=0;i<newSel.length;i++){
newSel[i].setAttribute('name',newSel[i].getAttribute('name')+'_'+(oRows.length-1));//sets the new incremented selects' names
newSel[i].setAttribute('value','');//clears the selects' values
}
root.appendChild(newRow);//appends the new row
root.insertBefore(newRow,document.getElementById('tot'));//appends the new row
}
function addT(n,f){
var re = /^[0-9]*$/;
var vTot='';
var oTab = document.getElementById('tab');// the table element
var oRows = oTab.getElementsByTagName('tr');// the rows collection
var cIndex= f.parentNode.cellIndex;//the index of the cell in row
for(var i=1;i<oRows.length-1;i++){
vTot = vTot*1+oRows[i].getElementsByTagName('input')[cIndex].getAttribute('value')*1;//calculates the total
}
document.forms[1].elements[n].value = vTot//assigns the total
}
</script>
</head>
<body>
<form name="payment_voucher" action="payment_save.jsp" method="post">
<fieldset >
<label> Narration:<input type="text" name="narration" size="60"></label><br>
</fieldset>
<tr>
<TD COLSPAN=6><center><h1><b>BANK PAYMENT INFORMATION</b></h1></center></TD>
</TR>
<table id="tab" width="600" border="3" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th>A/C Cd.</th>
<th>Description</th>
<th>S.L Code</th>
<th>Description1</th>
<th>Debit</th>
<th>Credit</th>
</tr>
<tr>
<td><input type="text" name="Ac.code" size="5" maxlength="5"></td>
<td> <input type="text" name="description" size="30"></td>
<td><input type="text" name="slcode" size="10" ></td>
<td> <input type="text" name="description1" size="30"></td>
<td><input type="text" name="debit" size="12" onkeyup="addT('tdebit',this)"></td>
<td> <input type="text" name="credit" size="12" onkeyup="addT('tcredit',this)"></td>
<tr id="tot">
<td>  </td>
<td>  </td>
<td> </td>
<td><center> TOTAL</center></td>
<td><input type="text" name="tdebit" size="12" > </td>
<td><input type="text" name="tcredit" size="12" > </td>
</tr>
</tbody>
</table>
<br>
<input type="submit" value="Submit" >
<input type="button" value="ADD" onclick="return addR()">
</form>
</body>
</html>