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

    Script in sovrapposizione

    Ciao a tutti,
    premetto che di JavaScript ne so davvero poco.
    Ho realizzato una pagina in PHP che include due differenti script: uno per gestire in modo alternativo i form (Niceforms) ed uno per realizzare una specie di div che si apre a tendina (Download sliding show/hide).
    Il mio problema è che se sono richiamati entrambi nella stessa pagina non riescono a coesistere a causa della seguente porzione di codice che sembra mandarli in "collisione":

    Script per il form
    Codice PHP:
    ....//Global Variables
    var niceforms document.getElementsByTagName('form'); var inputs = new Array(); var labels = new Array(); var radios = new Array(); var radioLabels = new Array(); var checkboxes = new Array(); var checkboxLabels = new Array(); var texts = new Array(); var textareas = new Array(); var selects = new Array(); var selectText "please select"; var agt navigator.userAgent.toLowerCase(); this.ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); var hovers = new Array(); var buttons = new Array(); var isMac = new RegExp('(^|)'+'Apple'+'(|$)');....... 
    Script per la tendina
    Codice PHP:
    ....function initShowHideDivs()
    {
        var 
    divs document.getElementsByTagName('DIV');
        var 
    divCounter 1;
        for(var 
    no=0;no<divs.length;no++){
            if(
    divs[no].className=='dhtmlgoodies_question'){
                
    divs[no].onclick showHideContent;
                
    divs[no].id 'dhtmlgoodies_q'+divCounter;
                var 
    answer divs[no].nextSibling;
                while(
    answer && answer.tagName!='DIV'){
                    
    answer answer.nextSibling;
                }
                
    answer.id 'dhtmlgoodies_a'+divCounter;    
                
    contentDiv answer.getElementsByTagName('DIV')[0];
                
    contentDiv.style.top contentDiv.offsetHeight 'px';     
                
    contentDiv.className='dhtmlgoodies_answer_content';
                
    contentDiv.id 'dhtmlgoodies_ac' divCounter;
                
    answer.style.display='none';
                
    answer.style.height='1px';
                
    divCounter++;
            }        
    ....... 
    Da quel poco che posso aver capito io, pare che l'istruzione
    Codice PHP:
    document.getElementsByTagName 
    essendo presente in entrambi gli script mi crei il problema.
    Qualcuno ha idea di cosa poter fare per far funzionare entrambi gli script nella stessa pagina?
    Grazie.... :master:

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    piuttosto saranno entrambi richiamati onload,
    se hai piu' di un window.onload devi accorparli, per es. hai
    window.onload=funzione1;
    ...
    window.onload=funzione2;

    rimuovi entrambi e aggiungi
    window.onload=function(){funzione1();funzione2}

    se hai voglia di spingerti un po' piu' avanti leggi qui
    http://forum.html.it/forum/showthrea...readid=1103803

  3. #3
    Gazie 1000 per la dritta!
    Ciao!

  4. #4
    Xinod, grazie al tuo suggerimento ho risolto alcuni dei mie problemi relativi all'utilizzo di più scripts.

    Purtroppo però quello relativo alla scomparsa/visibilità di un div continua a darmi problemi.
    Se questo è lo script originale
    Codice PHP:
    <script type="text/javascript">
    /************************************************************************************************************
    (C) [url]www.dhtmlgoodies.com,[/url] November 2005

    This is a script from [url]www.dhtmlgoodies.com.[/url] You will find this and a lot of other scripts at our website.    

    Terms of use:
    You are free to use this script as long as the copyright message is kept intact. However, you may not
    redistribute, sell or repost it without our permission.

    Thank you!

    [url]www.dhtmlgoodies.com[/url]
    Alf Magne Kalleland

    ************************************************************************************************************/

    var dhtmlgoodies_slideSpeed 10;    // Higher value = faster
    var dhtmlgoodies_timer 10;    // Lower value = faster

    var objectIdToSlideDown false;
    var 
    dhtmlgoodies_activeId false;
    var 
    dhtmlgoodies_slideInProgress false;
    function 
    showHideContent(e,inputId)
    {
        if(
    dhtmlgoodies_slideInProgress)return;
        
    dhtmlgoodies_slideInProgress true;
        if(!
    inputId)inputId this.id;
        
    inputId inputId '';
        var 
    numericId inputId.replace(/[^0-9]/g,'');
        var 
    answerDiv document.getElementById('dhtmlgoodies_a' numericId);

        
    objectIdToSlideDown false;
        
        if(!
    answerDiv.style.display || answerDiv.style.display=='none'){        
            if(
    dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){            
                
    objectIdToSlideDown numericId;
                
    slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
            }else{
                
                
    answerDiv.style.display='block';
                
    answerDiv.style.visibility 'visible';
                
                
    slideContent(numericId,dhtmlgoodies_slideSpeed);
            }
        }else{
            
    slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
            
    dhtmlgoodies_activeId false;
        }    
    }

    function 
    slideContent(inputId,direction)
    {
        
        var 
    obj =document.getElementById('dhtmlgoodies_a' inputId);
        var 
    contentObj document.getElementById('dhtmlgoodies_ac' inputId);
        
    height obj.clientHeight;
        if(
    height==0)height obj.offsetHeight;
        
    height height direction;
        
    rerunFunction true;
        if(
    height>contentObj.offsetHeight){
            
    height contentObj.offsetHeight;
            
    rerunFunction false;
        }
        if(
    height<=1){
            
    height 1;
            
    rerunFunction false;
        }

        
    obj.style.height height 'px';
        var 
    topPos height contentObj.offsetHeight;
        if(
    topPos>0)topPos=0;
        
    contentObj.style.top topPos 'px';
        if(
    rerunFunction){
            
    setTimeout('slideContent(' inputId ',' direction ')',dhtmlgoodies_timer);
        }else{
            if(
    height<=1){
                
    obj.style.display='none'
                if(
    objectIdToSlideDown && objectIdToSlideDown!=inputId){
                    
    document.getElementById('dhtmlgoodies_a' objectIdToSlideDown).style.display='block';
                    
    document.getElementById('dhtmlgoodies_a' objectIdToSlideDown).style.visibility='visible';
                    
    slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);                
                }else{
                    
    dhtmlgoodies_slideInProgress false;
                }
            }else{
                
    dhtmlgoodies_activeId inputId;
                
    dhtmlgoodies_slideInProgress false;
            }
        }
    }



    function 
    initShowHideDivs()
    {
        var 
    divs document.getElementsByTagName('DIV');
        var 
    divCounter 1;
        for(var 
    no=0;no<divs.length;no++){
            if(
    divs[no].className=='dhtmlgoodies_question'){
                
    divs[no].onclick showHideContent;
                
    divs[no].id 'dhtmlgoodies_q'+divCounter;
                var 
    answer divs[no].nextSibling;
                while(
    answer && answer.tagName!='DIV'){
                    
    answer answer.nextSibling;
                }
                
    answer.id 'dhtmlgoodies_a'+divCounter;    
                
    contentDiv answer.getElementsByTagName('DIV')[0];
                
    contentDiv.style.top contentDiv.offsetHeight 'px';     
                
    contentDiv.className='dhtmlgoodies_answer_content';
                
    contentDiv.id 'dhtmlgoodies_ac' divCounter;
                
    answer.style.display='none';
                
    answer.style.height='1px';
                
    divCounter++;
            }        
        }    
    }
    window.onload initShowHideDivs;


    </script> 
    ho provato a trasformare l'ultima parte del codice in

    Codice PHP:
    .
    .
    .
    .
    window.onload=function(){initShowHideDivs}

    </script> 
    per vedere se continua a funzionare, ma così non è.
    La cosa strana è che con il tuo suggerimento sono riuscita ad accorpare più scripts sotto un unico window.onload, ma quello sopra non vuole proprio saperne....

  5. #5
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    se la funzione da richiamare e' direttamente associata al gestore evento
    window.onload = initShowHideDivs;
    non vuole parentesi tonde

    ma se aggiungi una funzione generica a contenere quella che avevi originariamente allora le tonde ci vanno
    window.onload = function(){initShowHideDivs();}

    ciao

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.