473,224 Members | 1,965 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,224 software developers and data experts.

Unwanted blank elements

Claus Mygind
571 512MB
When I examine the arrays I have created, I see these extra commas (blank elements) inserted before each entry. They are blank elements, but I do not know why the code generates them (see code snippet).

I loop through the options array of the select element in my function and only add elements to the array if they have been selected. So what is happening?

,,,,,,,,,,,,,,,15. Layout,,,,,,,,,,,,,,,,,,,,,,,,,40. Enviromental,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,70. Concrete and Asphalt Lab.
15
"15. Layout"
40
"40. Enviromental"
70
"70. Concrete and Asphalt Lab."

Expand|Select|Wrap|Line Numbers
  1.            <select
  2.             id  ="PHASECODE"
  3.             name="PHASECODE"
  4.             class="InputText"
  5.             disabled="disabled"
  6.             multiple="multiple"
  7.             size="10"
  8.         >
  9.             <option value="10">10. Drilling</option>
  10.             <option value="15">15. Layout</option>
  11.             <option value="30">30. Geotechnical Eng.</option>
  12.             <option value="40">40. Enviromental</option>
  13.             <option value="50">50. Design Services</option>
  14.             <option value="60">60. Construction Material Eng.</option>
  15.             <option value="70">70. Concrete and Asphalt Lab.</option>
  16.             <option value="80">80. Soils Lab.</option>
  17.             <option value="92">92. Maint. Shop Activites</option>
  18.         </select>
  19.         <input
  20.             type="button" 
  21.             id="bAddPhaseCodes" 
  22.             value="Add more Depts. to this template" 
  23.             onclick="addPhase(this);"
  24.         >
  25.  
  26. function addPhase(obj)
  27. {
  28.   cGroupName = document.getElementById("GROUPNAME").value;
  29.   cDept = document.getElementById("JDEPTID").value;
  30.   for (var i = 0; i < document.getElementById("PHASECODE").options.length; i++ )
  31.   {
  32.     if ( document.getElementById("PHASECODE").options[i].selected )
  33.     {
  34.      aPhaseCodes[document.getElementById("PHASECODE").options[i].value] = document.getElementById("PHASECODE").options[i].text; 
  35.    }
  36.   }
  37.  
  38.     //add phase codes to department array
  39.     aDept[cDept] = aPhaseCodes
  40.  
  41.     //add department array to group name (template) array
  42.     aTemplates[cGroupName] = aDept;
  43. alert(aPhaseCodes.length);
  44. }
  45.  
  46.  
Oct 28 '08 #1
3 1167
acoder
16,027 Expert Mod 8TB
You're using the value as an index. When you set the index greater than the length of the array, the array automatically increases the size and fills the indices in between with blanks or undefined.
Oct 28 '08 #2
Claus Mygind
571 512MB
Thank you very much.

My workaround to using the number as a label in the array was to add a blank after the value. Will that cause me problems when examining the array?

Expand|Select|Wrap|Line Numbers
  1.  
  2. if ( document.getElementById("PHASECODE").options[i].selected )
  3. {
  4.   cWk = document.getElementById("PHASECODE").options[i].value+' ';
  5.   aPhaseCodes[cWk] = document.getElementById("PHASECODE").options[i].text; 
  6. }
  7.  
Oct 28 '08 #3
acoder
16,027 Expert Mod 8TB
It can because it's using object syntax, but you could just use a for..in loop. One other option is to use an object {}.
Oct 28 '08 #4

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

Similar topics

3
by: Buz | last post by:
I am having a problem with extra, unwanted space showing up on my web form tables. I've tried hand coding and can get the htm file to display fine. But as soon as I bring the form into Visual...
1
by: Me | last post by:
I need to test for blank inputs and run a routine "if" the input is blank. This will be used internally on a LAN to calculate selling price if the "sell" input is blank and a margin is supplied,...
3
by: Jeff Calico | last post by:
Hello everyone I am transforming an XML document to text, basically only outputting a small portion of it. When I run the following XSLT via Xalan's processor, I get a bunch of unwanted blank...
5
by: Tom | last post by:
I am having a problem where an extra gap (whitespace, padding) appears in a table cell where I don't want it. The data fed in the table is via dynamic HTML, so the amount in the middle cell may...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.