Hi,
I have a field in jsp page that has some textboxes. but the texboxes are dynamically created depending on the no of rows in a table.
When i click the update button in my jsp page it has to get the values in the text boxes and get the total.
My java script first checks if the field is valid i.e if there are any textbox in the field. If there are no fields then it set a variable as false. but if there are any fields it takes the length of the field to determine the no of textboxes and iterates through each text box to add all the value. The javascript works fine if there are no textboxs or if there are more then one textbox..
But when i have only one textbox in the field the field.length command returns me the value 'undefined'.
Below is the part of my java script code.
[CODE=javascript]function validateSupplie rCost()
{
var bValid = false;
if(document.dci sForm.txtTotalC ompEstimate){
bValid = true;}
var totalCompEstima te = document.dcisFo rm.txtTotalComp Estimate;
var supplierCostRes ponseGrp = document.dcisFo rm.rbCost;
var respInvest = document.dcisFo rm.C5;
var respDieMod = document.dcisFo rm.C4;
var respPartMod = document.dcisFo rm.C2;
var respOther = document.dcisFo rm.C1;
var bResponseType = false;
if(respInvest.c hecked == true || respDieMod.chec ked == true || respPartMod.che cked == true|| respOther.check ed == true) {
bResponseType = true;
}
var bSupplierRespon se = false;
for (var i =0; i< supplierCostRes ponseGrp.length ; i++)
{
if (supplierCostRe sponseGrp[i].value == "Y") {
if (supplierCostRe sponseGrp[i].checked == true) {
bSupplierRespon se = true;
}
}
}
if(bSupplierRes ponse == true && bResponseType == true) {
if(bValid == true){
var noOfFields = totalCompEstima te.length;
var totalCost = 0;
var cost = 0;
for(i=0; i< noOfFields; i++)
{
cost = totalCompEstima te[i].value;
totalCost = totalCost + cost;
}
if(totalCost > 0){
return true;
} else {
return false;
}
}else {
var compEstimate = document.dcisFo rm.txtCompEstim ate;
if(compEstimate .value >0){
return true;
} else {
return false;}
}
} else {
return true;
}
}[/CODE]
I have a field in jsp page that has some textboxes. but the texboxes are dynamically created depending on the no of rows in a table.
When i click the update button in my jsp page it has to get the values in the text boxes and get the total.
My java script first checks if the field is valid i.e if there are any textbox in the field. If there are no fields then it set a variable as false. but if there are any fields it takes the length of the field to determine the no of textboxes and iterates through each text box to add all the value. The javascript works fine if there are no textboxs or if there are more then one textbox..
But when i have only one textbox in the field the field.length command returns me the value 'undefined'.
Below is the part of my java script code.
[CODE=javascript]function validateSupplie rCost()
{
var bValid = false;
if(document.dci sForm.txtTotalC ompEstimate){
bValid = true;}
var totalCompEstima te = document.dcisFo rm.txtTotalComp Estimate;
var supplierCostRes ponseGrp = document.dcisFo rm.rbCost;
var respInvest = document.dcisFo rm.C5;
var respDieMod = document.dcisFo rm.C4;
var respPartMod = document.dcisFo rm.C2;
var respOther = document.dcisFo rm.C1;
var bResponseType = false;
if(respInvest.c hecked == true || respDieMod.chec ked == true || respPartMod.che cked == true|| respOther.check ed == true) {
bResponseType = true;
}
var bSupplierRespon se = false;
for (var i =0; i< supplierCostRes ponseGrp.length ; i++)
{
if (supplierCostRe sponseGrp[i].value == "Y") {
if (supplierCostRe sponseGrp[i].checked == true) {
bSupplierRespon se = true;
}
}
}
if(bSupplierRes ponse == true && bResponseType == true) {
if(bValid == true){
var noOfFields = totalCompEstima te.length;
var totalCost = 0;
var cost = 0;
for(i=0; i< noOfFields; i++)
{
cost = totalCompEstima te[i].value;
totalCost = totalCost + cost;
}
if(totalCost > 0){
return true;
} else {
return false;
}
}else {
var compEstimate = document.dcisFo rm.txtCompEstim ate;
if(compEstimate .value >0){
return true;
} else {
return false;}
}
} else {
return true;
}
}[/CODE]
Comment