473,765 Members | 1,968 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 #1
12 1636
On Sun, 05 Oct 2008 15:38:49 -0400, sheldonlg <sheldonlgwrote :
>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.
Pleast post question to comp.lang.javas cript.
This group is about basic html.
Oct 5 '08 #2
On Oct 5, 9:17*pm, richard <mem...@newsguy .comwrote:
On Sun, 05 Oct 2008 15:38:49 -0400, sheldonlg <sheldonlgwrote :
>>
Pleast post question to comp.lang.javas cript.
This group is about basic html.- Hide quoted text -

For one of the two values of this, it is. Check where you are
writing.

--
(c) John Stockton, near London, UK. Posting with Google.
Mail: J.R.""""""""@ph ysics.org or (better) via Home Page at
Web: <URL:http://www.merlyn.demo n.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Delphi, JavaScript, ....|
Oct 5 '08 #3
On 10/05/08 12:38 pm, sheldonlg wrote:
>
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.
How is that "array of text fields" created in HTML?
What I want to do is in javascript set the value of an individual
element, say a[3]. I have tried many combinations of
PHP is a server-side program. Javascript is a client-side language. What
exists in PHP on the server is not accessible by the client.
Using document.getEle mentById() is ineffective since the ID attribute
must be unique within a document.
Using document.getEle mentsByName() might work by calling it repeatedly
until a null is returned. But not all browsers work that way. (ISTR some
browsers return only the first instance, others only the last, yet others
all of them.)
BTW: What happens for a client that has JS disabled?
>
Any time I create an 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.
An URL to a test case would be most useful.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Oct 5 '08 #4
I finally got it to where it works (www.sheldonlg.com/t.php)

The simple answer was to have the names and ids all as "a[]". The
javascript does:

obj = document.getEle mentsByName('t[]');

and the values are at obj[i].value.
Oct 6 '08 #5
On 10/05/08 06:10 pm, sheldonlg wrote:
I finally got it to where it works (www.sheldonlg.com/t.php)
Oddly, the "js" button does nothing. Is it supposed to?
The simple answer was to have the names and ids all as "a[]". The
javascript does:
And is invalid markup. IDs are required to be unique within a document.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Oct 6 '08 #6
Jim Moe <jm************ ***@sohnen-moe.comwrote:
sheldonlg wrote:
>I finally got it to where it works *(www.sheldonlg.com/t.php)

* Oddly, the "js" button does nothing. Is it supposed to?
It alerts 11 and 22 in a row here. Maybe it does work work with you
because the markup is not Valid, duplicate IDs aside:

<http://validator.w3.org/check?verbos...uri=http%3A%2F
%2Fwww.sheldonl g.com%2Ft.php>
The simple answer was to have the names and ids all as "a[]". *The
javascript does:

* And is invalid markup. IDs are required to be unique within a document.
But not names.

BTW, you should fix your borken sender address so as to comply with
Internet standards and Netiquette.
F'up2 cljs

PointedEars
Oct 6 '08 #7
Thomas 'PointedEars' Lahn wrote:
Jim Moe <jm************ ***@sohnen-moe.comwrote:
>sheldonlg wrote:
>>I finally got it to where it works (www.sheldonlg.com/t.php)
Oddly, the "js" button does nothing. Is it supposed to?

It alerts 11 and 22 in a row here. Maybe it does work work with you
because the markup is not Valid, duplicate IDs aside:

<http://validator.w3.org/check?verbos...uri=http%3A%2F
%2Fwww.sheldonl g.com%2Ft.php>
>>The simple answer was to have the names and ids all as "a[]". The
javascript does:
And is invalid markup. IDs are required to be unique within a document.

But not names.

BTW, you should fix your borken sender address so as to comply with
Internet standards and Netiquette.
F'up2 cljs

PointedEars
I fixed a couple of errors.

1 - Yes, the ids of t[] can all be removed as there is no need for these
ids and ids should not be duplicates. I used getElementsByNa me.

2 - The complaint about the semi-colon in
for (i=0; i<obj.length; i++) {
is weird. That occurs between a <script></scriptinside the javascript
function. That is a proper specification for a for-loop. Why did it
complain? Here is the function:

<script type="text/javascript">
function dojs() {
var obj = document.getEle mentsByName('t[]');
for (i=0; i<obj.length; i++) {
alert('t[' + i + '] = ' + obj[i].value);
}
}
</script>
Oct 6 '08 #8
sheldonlg <sheldonlgwrote :
Thomas 'PointedEars' Lahn wrote:
<http://validator.w3.org/check?verbos...uri=http%3A%2F
%2Fwww.sheldonl g.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:

for (var i = 0, len = obj.lengh; i < len; i++)
{
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.

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.

And apparently your sender header is borken as well. Fix it.
PointedEars
Oct 6 '08 #9
On 10/06/08 02:32 am, Thomas 'PointedEars' Lahn wrote:
>
BTW, you should fix your borken sender address so as to comply with
Internet standards and Netiquette.
Please be more specific.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Oct 6 '08 #10

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

Similar topics

4
2343
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
3977
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
1779
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
34391
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
1171
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
9568
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
10007
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...
0
9833
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...
0
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
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
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.