Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: AW: [Javascript] addin <input fields> via visibility or similar?


  • From: junado at junado.com (Julien Nadeau)
  • Subject: AW: AW: [Javascript] addin <input fields> via visibility or similar?
  • Date: Mon Sep 26 06:34:14 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@xxxxxxxxxx

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@xxxxxxxxxx
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.LaTech.edu/pipermail/javascript/attachments/20050926/d8aad857/attachment.html