Accessing an array of HTML input text boxes using jQuery or plain Javascript?

First of all id attribute cannot contains or character There is lots of ways to get jQuery/plain JavaScript references to these elements. You can use descendant selector: fieldset id="list-of-fields"> $("#list-of-fields input"); document. GetElementById("list....").

GetElementsByTagName("input") You can also use attribute selector: $("inputname^=field") I'm not sure whether that's the only way but I think in plain JavaScript you'll have to fetch all input elements ( document. GetElementsByTagName ) and then loop through array of these elements and check each element (whether it has name attribute which value starts with field ).

First of all, id attribute cannot contains or character. There is lots of ways to get jQuery/plain JavaScript references to these elements. You can use descendant selector: $("#list-of-fields input"); document.

GetElementById("list...."). GetElementsByTagName("input"); You can also use attribute selector: $("inputname^=field"); I'm not sure whether that's the only way but I think in plain JavaScript you'll have to fetch all input elements (document. GetElementsByTagName) and then loop through array of these elements and check each element (whether it has name attribute which value starts with field).

Give each element a class and access the group using jQuery: Field 1: Field 2: jQuery: $("input. Fields"). Each(function (index) { // Your code here }); This will run the anonymous function on each input element with a classname of "fields", with the this keyword pointing to the current element.

See api.jquery.com/each/ for more info.

That's interesting. So the name field can include s but the ID can't. So at least from a PHP point of view, I'd still be able to treat the $_POST'field' data as an array?

And using $("inputname=field1").val() I can still access the value using jQuery. So the key is to use name and not depend on ID. – greggannicott Feb 3 '10 at 13:46 @greggannicott: Square brackets are permitted in name attributes but not in ID attributes.

I think the correct way to use it for PHP is just have name="field" for each and not name="fieldn" but I could be mistaken and both might work. – Andy E Feb 3 '10 at 13: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