473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Field.length returns undefined

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.

Expand|Select|Wrap|Line Numbers
  1. function validateSupplierCost()
  2.     {    
  3.         var bValid = false;
  4.         if(document.dcisForm.txtTotalCompEstimate){
  5.             bValid = true;}
  6.         var totalCompEstimate = document.dcisForm.txtTotalCompEstimate;
  7.         var supplierCostResponseGrp = document.dcisForm.rbCost;
  8.         var respInvest = document.dcisForm.C5;
  9.         var respDieMod = document.dcisForm.C4;
  10.         var respPartMod = document.dcisForm.C2;
  11.         var respOther = document.dcisForm.C1;
  12.         var bResponseType = false;
  13.         if(respInvest.checked == true || respDieMod.checked == true || respPartMod.checked == true|| respOther.checked == true) {
  14.             bResponseType = true;
  15.         }
  16.         var bSupplierResponse = false;
  17.  
  18.         for (var i =0; i< supplierCostResponseGrp.length; i++) 
  19.             {
  20.                 if (supplierCostResponseGrp[i].value == "Y") {
  21.                     if (supplierCostResponseGrp[i].checked == true) {
  22.                         bSupplierResponse = true;
  23.                     }
  24.                 }
  25.             }
  26.         if(bSupplierResponse == true && bResponseType == true) {
  27.         if(bValid == true){    
  28.         var noOfFields = totalCompEstimate.length;
  29.         var totalCost = 0;
  30.         var cost = 0;
  31.         for(i=0; i< noOfFields; i++)
  32.             {
  33.                 cost = totalCompEstimate[i].value;
  34.                 totalCost = totalCost + cost;
  35.             }
  36.             if(totalCost > 0){
  37.                 return true;
  38.             } else {
  39.                 return false;
  40.             }
  41.         }else {
  42.             var compEstimate = document.dcisForm.txtCompEstimate;
  43.             if(compEstimate.value >0){
  44.                 return true;
  45.             } else {
  46.                 return false;}
  47.         }
  48.         } else {
  49.             return true;
  50.         }    
  51.     }
Aug 31 '07 #1
1 2490
dmjpro
2,476 2GB
Welcome to TSDN.

Glad to see you that you are following Posting Guidelines.
Anyway, you have a line in JavaScript.

Expand|Select|Wrap|Line Numbers
  1. var supplierCostResponseGrp = document.dcisForm.rbCost;
  2. //Changes this line....
  3. var supplierCostResponseGrp = document.getElementsByName('rbCost');
  4. //Into this one and see the what hapens!
  5.  
Best of luck with your code.

Kind regards,
Dmjpro.
Aug 31 '07 #2

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

Similar topics

3
by: Richard | last post by:
I have written a static method that uses the Reflection API to scrape all of the names of the instance variables in a class and their corresponding values; and then returns a hashMap containing a...
7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
6
by: Mark Anderson | last post by:
I'm getting a bit confused, it seems a checkbox object only has a length value if there is more than one checkbox of that name, 2 checkboxes named 'box' have a length of 2 but a single box returns...
3
by: Dag Sunde | last post by:
....while MyArray.toString() returns the expected value... I have a function that returns an array: function getProducts( auctionID ) { var prodCount = 0; var prodArray = new Array() for(...
4
by: Tom Esker | last post by:
I've got Javascript in a form that adds up all of the numbers in a column of form fields and displays a total. It works great if every field has an initial value of 0, but if any of them are null,...
8
by: tshad | last post by:
I have a function that formats currency to add commas and $. But I also check to see if the field is empty and if it is I return. The problem is that the field now contains the word...
1
by: Matt | last post by:
I could use some help dealing with null blobs. I'm returning a transaction from an Image BLOB field in SQL Server 2000 using C#. If the transaction exists the value is returned with out trouble,...
7
by: Tizzah | last post by:
What is wrong with that? regex = /^(http|https):\/\/+({1}+)*\.{2,5}(({1,5})?\/.*)?$/ if(field.hpage.value != regex.test(field.hpage.value)){ alert("Bad Homepage") field.hpage.focus()...
6
by: Richard | last post by:
Which way would you guys recommened to best parse a multiline file which contains two fields seperated by a tab. In this case its the linux/proc/filesystems file a sample of which I have included...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.