HTML form input tag name element array with JavaScript?

1. ) First off, what is the correct terminology for an array created on the end of the name element of an input tag in a form? Confusing PHPism As far as JavaScript is concerned a bunch of form controls with the same name are just a bunch of form controls with the same name, and form controls with names that include square brackets are just form controls with names that include square brackets The PHP naming convention for form controls with the same name is sometimes useful (when you have a number of groups of controls so you can so things like: input name="name1"> ) How do I get the information from that array with JavaScript?

Get the "name of form control" property of the elements property of the form. Since the name of the form controls includes square brackets, you can't use dot notation and have to use square bracket notation Since you have multiple elements with that name, it will be a collection rather then a single control, so you can loop over it with a standard for loop that makes use of its length property var myForm = document.forms. Id_of_form; var myControls = myForm.

Elements'p_id'; for (var I = 0; I.

1. ) First off, what is the correct terminology for an array created on the end of the name element of an input tag in a form? "Confusing PHPism".

As far as JavaScript is concerned a bunch of form controls with the same name are just a bunch of form controls with the same name, and form controls with names that include square brackets are just form controls with names that include square brackets. The PHP naming convention for form controls with the same name is sometimes useful (when you have a number of groups of controls so you can so things like: ) … but is mostly just confusing. 2.) How do I get the information from that array with JavaScript?

Get the "name of form control" property of the elements property of the form. Since the name of the form controls includes square brackets, you can't use dot notation and have to use square bracket notation. Since you have multiple elements with that name, it will be a collection rather then a single control, so you can loop over it with a standard for loop that makes use of its length property.

Var myForm = document.forms. Id_of_form; var myControls = myForm. Elements'p_id'; for (var I = 0; I.

Thanks, this is exactly what I was looking for. I modified it a little though... for(i = 0; I Length; i++) – typoknig Jul 13 '10 at 6:13 Using I as a global isn't a good idea (it is just asking for scoping issues to bite you, either now or in the future because you have got into bad habits). Using document.

Form is bad practice because (a) the document. Forms collection will make it clearer what you are doing and form isn't a very detailed name (and document. Form could be confused with document.

Forms which makes maintenance more confusing. Scrunching things up on to a single line is fine though, I was just more explicit so you could see what is going on. – Quentin Jul 13 '10 at 6:20.

Document.form. P_id. Length ... not count().

You really should give your form an id Then refer to it using: var theForm = document. GetElementById("myform"); Then refer to the elements like: for(var I = 0; I Length; i++){.

Thanks, but this does not work – typoknig Jul 13 '10 at 4:55.

Try this something like this: var p_ids = document. Forms0. Elements"p_id"; alert(p_ids.

Length); for (var I = 0, len = p_ids. Length; I.

Thanks, but this does not work – typoknig Jul 13 '10 at 4:56 It is surely work. Otherwise you did anything wrong in somewhere... – Karthik Jul 13 '10 at 6:08 It doesn't work. JavaScript doesn't have a count method built it, and you can't use or in a property name that you access via dot notation.As for your second example, the fields are named p_id not p_id.

– Quentin Jul 13 '10 at 7:03.

To answer your questions in order: 1) There is no specific name for this. It's simply multiple elements with the same name (and in this case type as well). Name isn't unique, which is why id was invented (it's supposed to be unique).2) function getElementsByTagAndName(tag, name) { //you could pass in the starting element which would make this faster var elem = document.

GetElementsByTagName(tag); var arr = new Array(); var I = 0; var iarr = 0; var att; for(; I.

Wow. That's just ugly. Using new Array() instead of , keeping a length tracker instead of using arr.

Length or arr.push(), initializing I outside the for loop, using getAttribute instead of just going for the name property, working globally instead of within a form, and all the get (more or less) the same results of document.forms.element. Elements_name. (Oh and getElementsByName could have been used too).

– Quentin Jul 13 '10 at 5:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions