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

Accessing arrays via DOM

I want to use an array for my fieldnames (field[1], field[2], etc.) instead of names like "first_name", "last_name", etc.

It works from an HTML standpoint, but I can't seem to access the contents of those text input fields from Javascript. The code below works 100% if I change "field[3]" to any normal variable name like "last_name".

Expand|Select|Wrap|Line Numbers
  1.     if (cust_last_name.length < 1) {
  2.         eval('document.forms.info.field[3].style.backgroundColor = "#FFCCCC";');
  3.         eval('document.forms.info.field[3].focus();');
  4.         alert("Please fill in the Last Name field.");
  5.         return false;
  6.     }
  7.  
How can I do what I'm trying to do?

Thanks,

Matthew
Feb 27 '08 #1
2 1041
hsriat
1,654 Expert 1GB
I want to use an array for my fieldnames (field[1], field[2], etc.) instead of names like "first_name", "last_name", etc.

It works from an HTML standpoint, but I can't seem to access the contents of those text input fields from Javascript. The code below works 100% if I change "field[3]" to any normal variable name like "last_name".

if (cust_last_name.length < 1) {
eval('document.forms.info.field[3].style.backgroundColor = "#FFCCCC";');
eval('document.forms.info.field[3].focus();');
alert("Please fill in the Last Name field.");
return false;
}

How can I do what I'm trying to do?

Thanks,

Matthew
I never tried anything like that, but if you really want to use arrays,
then you may use the standard DOM array, ie. elements[ ]

You do not need to provide elements[ ] as name to the form items.
Feb 27 '08 #2
acoder
16,027 Expert Mod 8TB
No need for eval either:
Expand|Select|Wrap|Line Numbers
  1.     if (cust_last_name.length < 1) {
  2.         document.forms["info"].elements["field[3]"].style.backgroundColor = "#FFCCCC";
  3.         document.forms["info"].elements["field[3]"].focus();
  4.         alert("Please fill in the Last Name field.");
  5.         return false;
  6.     }
  7.  
Feb 28 '08 #3

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

Similar topics

15
by: Christopher Benson-Manica | last post by:
When are named elements written with script accessible to script? <html><head><script type="text/javascript"> function ready() { alert( document.getElementsByName("div").length ); }...
3
by: Christopher Benson-Manica | last post by:
I appreciate all the responses to my earlier post about accessing named elements. However, I'm still wondering about my actual problem, which is that I need to initialize some arrays of named...
2
by: George W. | last post by:
In perl I'm used to using hashtables of arrays and accessing a particular element like this: $HoA{flintstones} Simple as that. How do I access and update values of arrays stored in my hashtable...
7
by: David | last post by:
Hi, I am having trouble with a form that I have loaded trying to access a procedure on the main form. The trouble seems to be that a Global Array that is declare in a Module is producing a...
0
by: YAH | last post by:
I don't know where to post this so I'll try here. I'm trying to create a C# based Windows Form app which hosts a webbrowser control, loads a webpage of mine, and after DocumentComplete extracts...
38
by: djhulme | last post by:
Hi, I'm using GCC. Please could you tell me, what is the maximum number of array elements that I can create in C, i.e. char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ; I've...
4
by: Michael Goerz | last post by:
Hi, What is the error in the code below? The output is: DEBUG: matrix.b is 2.000000 DEBUG: matrix->b is 0.000000 In other words, the struct is empty after it is passed to the solve_tridiag...
3
by: sam | last post by:
hello all, i am currently in the process of planning a piece of software to model polymerisation kinetics, and intend to use python for all the high-level stuff. the number-crunching is...
15
by: bernd | last post by:
Hi folks, a simple question for the experts, I guess. Obviously I am doing something wrong when trying to access an element of an array declared within a structure: #include <stdio.h>...
16
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.