Mad_T;10999646 wrote:
Is there anyway to remove the div and have it done via the input fields name or id ??
Not in regard to markup since that would produce invalid markup. As per the specification, the form element can only contain block level elements, such as div, p and fieldset. Thus, you can't remove your div element unless you replace it with something of similar nature.
Thus, this is invalid. Neither input, label or br are allowed there.
Mad_T;10999646 wrote:
<form name="form1" action="#" method="post">
<input type="checkbox" id="checkmain1" /><label for="checkmain1">Enable/Disable</label><br />
[/htm]
[/quote]
Next up on the list of invalid stuff is your use of identical ids across the document. Each id has to be unique across the entire document. As such, this is also invalid.
[QUOTE=Mad_T;10999646]
[code=html]
<input id="vals" />
<input id="vals" />
When it comes to javascript, there are several ways of achieving your goal. However, if you can manage to do so using an id in the containing element, why do you even bother NOT doing just that? Either way there are several possibilities. When it comes to the DOM API, Mozilla's DOM reference is good. This is where you can find methods such as getElementsByName on your own. You find the jQuery API spec docs here, and the stuff that you are after in this case is found in the "selectors" subsection.
/*
* Using javascript DOM API
*/
var d = document;
/*
* Method does not exist for elements, only for document.
*/
var els = d.getElementsByName('apa[]');
var s = '*** DOM API ***\nFirst\n';
for (var i = 0; i < els.length; ++i)
{
s += els[i].textContent;
}
/*
* Start by retrieving the containing element, for example by id.
*/
var test = d.getElementById('container');
/*
* Proceed to get the contained elements you are looking for
* and then use that element to retrieve the rest.
*/
var els = test.getElementsByTagName('div');
s += '\n\nSecond\n';
for (var i = 0; i < els.length; ++i)
{
s += els[i].textContent;
}
/*
* Using jQuery makes things a lot easier. You can even
* specify selection for both element type, name, className
* and other attributes at the same time, using the same syntax
* you would for CSS selectors.
*
* Moreover, you no longer have to worry about browser
* inconsistencies.
*/
s += '\n\n\n*** jQuery ***\n';
/*
* Find el with id "container" then check it for children that are
* divs with className "odd" and name "apa".
* Then iterarte over the collection.
*/
$('#container > div.odd[name=apa\\[\\]]').each(function(){ s += this.textContent; });
alert(s);