AW: AW: [Javascript] addin <input fields> via visibility or similar?
Julien Nadeau
junado at junado.com
Mon Sep 26 06:34:09 CDT 2005
You can probably use:
var ordersNumRows = document.getElementsByTagName("input").length;
if you have to count all your input fields, then alter that value by
the amount of fixed, non counted, input fields.
Otherwise, if you really want a bullet proof method, you'll have to
use something like this:
function countRows() {
var orderNumRows = 0;
var inputFields = document.getElementsByTagName("input")
var numTag = inputFields.length;
for (i=0; i<numTag; i++) {
if (inputFields[i].getAttribute("name") == "test[]") {
orderNumRows++;
}
}
alert(orderNumRows);
}
This returned "2" for the following HTML:
<input name="test[]" type="text" />
<input name="test[]" type="text" />
<input name="other" type="text" />
Hope this helps,
Julien Nadeau
junado at junado.com
Le 05-09-26 à 05:56, Michael Borchers a écrit :
> Michael Borchers wrote:
>
>>
>> beautiful, this works so far.
>> the name for the inputs will be something like
>> products_id[X][products_price]
>>
>> how can i count how many rows (X) there are already?
>>
>
> Triche wrote:
>
>> If by "rows" you mean extant INPUT tags, use getElementsByTagName,
>> then
>> loop through and count up the ones that match the stable portion
>> of your
>> NAME attribute.
>>
>
> how exactely do i count through? javascript doesn't have a simple
> count function for that or? :(
>
> a simple
> var ordersNumRows = count(document.getElementById("products_id[]"));
>
> would have been nice;)
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050926/d8aad857/attachment.htm>
More information about the Javascript
mailing list