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

    Controllare se esiste una variabile

    Come si scrive, in javascript, un if per controllare se esiste una variabile...e se questa esiste eseguire le istruzioni nell'if...ho provato a scriverlo come faccio di solito nel php "if (variabile!=0) {...istruzioni...} , ma non funziona...Non sono bravo a programmare in javascript quindi perdonate la mia ignoranza
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  2. #2
    Utente bannato
    Registrato dal
    Mar 2005
    Messaggi
    136
    Codice PHP:
    if(m_Variabile == null

  3. #3
    mi da sempre come errore

    ' variabile ' non è definito

    Ma è questo il punto...io vorrei fare in modo che, se la variabile è esiste, è definita...allora parte con le istruzioni...se non lo è...passa avanti...però non funziona...

    Domanda: Quel "m_" prima della variabile è necessario??
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  4. #4
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    codice:
    var v1 = null;
    function button1_onclick() {
    	if(self.v1 !== undefined) alert(v1); else alert("v1 non definito");
    	if(self.v2 !== undefined) alert(v2); else alert("v2 non definito");
    }
    Pietro

  5. #5
    nulla...ora mi dice che undefined non è definito...

    è importante se c'è scritto Javascript 1.2 all'inizio dello script??
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  6. #6
    <script language="JavaScript1.2">

    function highlightit(cur2){
    if (cur2.filters.alpha.opacity<100)
    cur2.filters.alpha.opacity+=5
    else if (window.highlighting)
    clearInterval(highlighting)
    }

    function dehighlightit(cur2){
    if (cur2.filters.alpha.opacity>0)
    cur2.filters.alpha.opacity-=5
    else if (window.dehighlighting)
    clearInterval(dehighlighting)
    }

    function high(which2){
    theobject=which2
    if (self.dehighlighting !== undefined)
    { clearInterval(dehighlighting)
    }
    highlighting=setInterval("highlightit(theobject)", 50)

    }

    function low(which2){
    theobject=which2
    if (self.highlighting !== undefined)
    { clearInterval(highlighting)
    }
    dehighlighting=setInterval("dehighlightit(theobjec t)",50)

    }



    </script>
    Questo è lo script...

    if (self.dehighlighting !== undefined)
    { clearInterval(dehighlighting)
    }

    if (self.highlighting !== undefined)
    { clearInterval(highlighting)
    }


    e questi due sono gli if che non funzionano...
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  7. #7
    Originariamente inviato da valepu
    nulla...ora mi dice che undefined non è definito...

    è importante se c'è scritto Javascript 1.2 all'inizio dello script??
    e così?

    codice:
    if(!variabile) alert("Variabile non definita.");
    ciao

  8. #8
    ancora nulla...
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  9. #9
    Alla fine ho risolto (avevo lasciato un pezzo di codice che non andava...), grazie lo stesso ^^
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

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 © 2026 vBulletin Solutions, Inc. All rights reserved.