473,770 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Basic array stuff

This is kind of basic, and I googled but didn't find much help.

I have an array of text element fields. They all need to have the same
name. So, let the name be either all with a[] or build individually as
a[0], a[1], a[2], etc. The brackets need to be there because I will
obtaining the values of them as an array using $_POST{'a'] in php.

What I want to do is in javascript set the value of an individual
element, say a[3]. I have tried many combinations of

1 - setting the ids all as
a) a
b) a[]
c) individually as a[0], a[1], etc.
2 - using document.getEle mentById
3 - using document.getEle mentsByName

Any time I create and object from the name, and then try to use that
object, I get "object has no properties" in Firebug. This is true
whether I try obj.value or obj[i].value.

So, please,
1 - How do I set the id attribute?
2 - How do I access or set an individual member in the array?
3 - For the name attribute, should I use a[] or individually build them
or does it not matter as far as javascript is concerned?

Yes, this is basic, but I have been going in circles for a few hours now
so any help will be appreciated.
Oct 5 '08
12 1638
Thomas 'PointedEars' Lahn wrote:
sheldonlg <sheldonlgwrote :
>Thomas 'PointedEars' Lahn wrote:
>><http://validator.w3.org/check?verbos...uri=http%3A%2F
%2Fwww.sheldo nlg.com%2Ft.php >
[...]
2 - The complaint about the semi-colon in
for (i=0; i<obj.length; i++) {

You did to declare `i', which is error-prone, and you have a property
resolved repeatedly, which is inefficient:
OK, I can but the resolving being inefficient and should have simply set
it once. However, I just don't understand what you are saying about

`i'

Where did I use that accent mark before the "i"?
>
for (var i = 0, len = obj.lengh; i < len; i++)
{
I think you have a typo here.
>is weird. That occurs between a <script></scriptinside the javascript
function. That is a proper specification for a for-loop. Why did it
complain?

Because in XHTML the content model of the `script' element is PCDATA,
not CDATA as in HTML. Therefore, `<' is regarded an STAGO (Start Tag
Open) delimiter and `;' is not part of a proper attribute name that is
expected in a start tag.
I don't understand what you are saying. Do you mean that because it is
defined as xhtml, that even though it is inside a javascript it treats
the "<" as an opening of a tag rather than as a "less than"? Is so,
then why would your suggestion abovenot have a complaint?
>
While the solutions for this "problem" are simple and have been
discussed also here several times -- Google is your friend [psf 6.1]
--, you should simply not declare XHTML when you don't know what you
are doing.
Apparently my default template in Dreamweaver for a new PHP file
produces that. I didn't pay much attention to it when I composed the
example case.
Oct 9 '08 #11
sheldonlg meinte:
OK, I can but the resolving being inefficient and should have simply set
it once. However, I just don't understand what you are saying about

`i'

Where did I use that accent mark before the "i"?
You should add *var* to declare it as a local variable. Perhaps you
should try JSLint to "validate" your scripts. It's a bit harsh on code
not following its guidelines, but a great tool to find such issues.
> for (var i = 0, len = obj.lengh; i < len; i++)
I think you have a typo here.
Yes, it should read "length".
>Because in XHTML the content model of the `script' element is PCDATA,
not CDATA as in HTML. Therefore, `<' is regarded an STAGO (Start Tag
Open) delimiter and `;' is not part of a proper attribute name that is
expected in a start tag.

I don't understand what you are saying. Do you mean that because it is
defined as xhtml, that even though it is inside a javascript it treats
the "<" as an opening of a tag rather than as a "less than"?
Yes.

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Oct 9 '08 #12
Thomas 'PointedEars' Lahn wrote:
sheldonlg <sheldonlgwrote :
> for (i=0; i<obj.length; i++) {
JFTR:
You did to declare `i', which is error-prone, and you have a property
s/to/not/
resolved repeatedly, which is inefficient:

for (var i = 0, len = obj.lengh; i < len; i++)
{
for (var i = 0, len = obj.length; i < len; i++)
{
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Oct 10 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2345
by: Glutinous | last post by:
I've been studying this for hours, searching the www & usenet, and still can't figure out why 'each' returns an array of four key/value pairs, when it looks like just two pairs would suffice... That is, it looks to me like & are the same, and also & , so what's the point of duplicating them?
54
3979
by: seberino | last post by:
Many people I know ask why Python does slicing the way it does..... Can anyone /please/ give me a good defense/justification??? I'm referring to why mystring gives me elements 0, 1, 2 and 3 but *NOT* mystring (5th element). Many people don't like idea that 5th element is not invited. (BTW, yes I'm aware of the explanation where slicing
2
5783
by: bbxrider | last post by:
i'm new to javascript but have programmed lots in vb, cobol, basic, etc jscript seems much more object oriented to me, much more direct manipulation of properties at least, than vb, don't know about methods yet i'm having trouble locating property 'trees' so to speak, at least for html/web and jscript objects like in this code: function MM_preloadImages() { var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var...
5
7235
by: K. Shier | last post by:
when attempting to edit code in a class file, i see the bug "Visual Basic ..NET compiler is unable to recover from the following error: System Error &Hc0000005&(Visual Basic internal compiler error) Save your work and restart Visual Studio .NET." has anyone seen this bug and can you confirm one way or the other whether or not it can corrupt your source files? (by 'corrupt' i mean: do anything to it that will cause it to fail to load and...
7
1780
by: MBS | last post by:
Greetings. I'm still pretty new to PHP and I have a question. I know that variables are preceeded by a "$" (dollar sign). Typically, a variable has one value, unless it is an array. Then it is essentially a pointer to numerous values sequential in memory. The code I'm looking at now is using the same variable name, but assigning a different "index" to it, if you will. For example, I see the following: $settings
21
34394
by: kent lavallie | last post by:
Hi. I am an amature c hobbyist and I wish to begin using malloc as I have been told that running executables from executables is a less than elegant way to manage memory use. I need basic examples so me and my compiler can get familliar with malloc. Please give examples that do not contain nested assignments and the like as I will get lost quite easily. As an example of my rudimentary style take a look at how I create an array and assign a...
13
2555
by: Karl Groves | last post by:
I'm missing something very obvious, but it is getting late and I've stared at it too long. TIA for responses I am writing a basic function (listed at the bottom of this post) that returns data from a query into an array. The intent is that the following code:
4
1173
by: Voli | last post by:
I have a question about: and i only know really basic c++ none of the really fancy stuff :( How to convert integers into a string/character array? and How do I search for specific integers in the string/character array? (all the input is integers)
14
1852
by: MartinRinehart | last post by:
Working on parser for my language, I see that all classes (Token, Production, Statement, ...) have one thing in common. They all maintain start and stop positions in the source text. So it seems logical to have them all inherit from a base class that defines those, but this doesn't work: import tok class code: def __init__( self, start, stop ):
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10102
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9910
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.