Ciao.
Qc ha sotto mano una funzione
che prenda come parametri un numero
n di strighe (nome dell'attributo name)
e restituisca un array di elementi che hanno
quel nome.
Si penso si capisse anche dal titolo![]()
![]()
Ciao.
Qc ha sotto mano una funzione
che prenda come parametri un numero
n di strighe (nome dell'attributo name)
e restituisca un array di elementi che hanno
quel nome.
Si penso si capisse anche dal titolo![]()
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Prova così:
codice:function getElementsByName(nome) { var collezione = new Array() var elementi = document.getElementsByTagName('*') for (var i = 0; i < elementi.length; i++) { if ( elementi.item(i).getAttribute('name') == nome ) { collezione.push(elementi.item(i)) } return collezione } }
Leading the Web to Its Full Potential...
www.pierofix.it | www.w3.org | www.zeldman.com/externals | http://browsehappy.com | www.alistapart.com | www.webstandards.org | www.flickr.com/photos/pierofix/
Ti ringrazio per la risposta.
Intendevo una cosa del genere:
Evitando di specificare nell'if i nomi che miCodice PHP:
function getFormElementsByName(){
var input= new Array();
var frm= document.getElementsByTagName('form')[0];
if(!frm){return;}
var elements= frm.elements;
for(var i=0;i<elements.length;i++){
var name= elements[i].getAttribute('name');
if(name=='id' || name=='date' || name=='content'){
input.push(elements[i]);
}
}
return input;
};
interessa salvare.
Cioè fare una cosa del genere:
getFormElementsByName('id','date','content')
Sono riuscito a fare una cosa del genere con php
usando array_intersect_key ma con js ho un po di problemi![]()
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Qc di + affidabileCodice PHP:
function getFormElementsByName(){
var input= new Array();
var args= arguments;
var frm= document.getElementsByTagName('form')[0];
var elements= frm.elements;
if(!frm){return;}
for(var i=0;i<elements.length;i++){
var name= elements[i].getAttribute('name');
if(args[i]==name){
input.push(elements[i]);
}
}
return input;
};
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it