Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    getFormElementsByName() ...........

    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

  2. #2
    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
       }
    }

  3. #3
    Ti ringrazio per la risposta.
    Intendevo una cosa del genere:
    Codice PHP:
    function getFormElementsByName(){
        var 
    input= new Array();
        var 
    frmdocument.getElementsByTagName('form')[0];
            if(!
    frm){return;}
        var 
    elementsfrm.elements;
        
        for(var 
    i=0;i<elements.length;i++){
            var 
    nameelements[i].getAttribute('name');
            if(
    name=='id' || name=='date' || name=='content'){
                    
    input.push(elements[i]);
            }
        }
             return 
    input;
    }; 
    Evitando di specificare nell'if i nomi che mi
    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

  4. #4
    Codice PHP:
    function getFormElementsByName(){
        var 
    input= new Array();
        var 
    argsarguments;
        var 
    frmdocument.getElementsByTagName('form')[0];
        var 
    elementsfrm.elements;
        if(!
    frm){return;}
        for(var 
    i=0;i<elements.length;i++){
            var 
    nameelements[i].getAttribute('name');
            if(
    args[i]==name){
                    
    input.push(elements[i]);
            }
        }
        return 
    input;
    }; 
    Qc di + affidabile


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.