Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Prototype select elements by name with mask

Tags:

prototypejs

I have several inputs:

<input name="row.type[0].value">
<input name="row.type[1].value">
....
<input name="row.type[100].value">

How can I to obtain an array with all these inputs?

If with $$-operation, then something like that doesn't work:

var cabins = $$('input[name^=row.type[].value]').each(function(row) {
   //stuff
});    
like image 425
Vladimir Kishlaly Avatar asked Jul 29 '26 05:07

Vladimir Kishlaly


2 Answers

If all the inputs you want to grab have a name starting with row.type[, then you can grab them all using $$() like this:

var cabins = $$('input[name^="row.type["]');
like image 122
Dimochka Avatar answered Aug 01 '26 04:08

Dimochka


if you add a class to all of the input fields you can access them using the class

for instance

<input class="rowvalues" name="row.type[0].value">
<input class="rowvalues" name="row.type[1].value">
....
<input class="rowvalues" name="row.type[100].value">

then using $$()

var cabins = $$('.rowvalues').each(function(row){
    //other code
    //row equals the DOM element not the input value
});
like image 43
Geek Num 88 Avatar answered Aug 01 '26 03:08

Geek Num 88



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!