Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    controllare che tutti i dati siano uguali e submit del form

    in un form devo controllare che tutti i dati "totali" siano uguali, e solo in caso affermativo devo procedere all'invio del form, altrimenti faccio un'alert; solo che senbra non funzionare, io ho fatto così:


    function guestForm(){
    var tot_israele = document.getElementById("tot_isr");
    var tot_vigo = document.getElementById("tot_vig");
    var tot_brasile = document.getElementById("tot_bra");
    var tot_grecia = document.getElementById("tot_gre");
    var tot_libia = document.getElementById("tot_lib");
    var tot_trieste = document.getElementById("tot_tri");
    var tot_mondial = document.getElementById("tot_mon");
    var tot_italia = document.getElementById("tot_ita");

    tot_israele = parseInt(tot_israele.value, 10);
    tot_vigo = parseInt(tot_vigo.value, 10);
    tot_brasile = parseInt(tot_brasile.value, 10);
    tot_grecia = parseInt(tot_grecia.value, 10);
    tot_libia = parseInt(tot_libia.value, 10);
    tot_trieste = parseInt(tot_trieste.value, 10);
    tot_mondial = parseInt(tot_mondial.value, 10);
    tot_italia = parseInt(tot_italia.value, 10);

    if (!(tot_israele == tot_vigo == tot_brasile == tot_grecia == tot_libia == tot_trieste == tot_mondial == tot_italia)){
    alert("controlla i dati");
    }
    }


    il problema è che non mi entra mai nell'if e non capisco come mai.
    mi sapete dire dove sbaglio?
    altra domanda che già che ci sono la faccio in questa discussione: se non compare l'alert dovrei inviare il form [fare quindi il submit], se faccio this.form.submit(); è corretto?

    ringrazio per un eventuale aiuto!
    Talvolta anche una persona apparentemente inutile si rivela un abile samurai dalla forza di mille uomini, dimostrando di poter rinunciare alla vita e che il suo cuore si è completamente identificato con quello del suo padrone

  2. #2
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Non entra nella if xche la sintassi è scoretta. JS aspetta && o || tra due condizioni.

  3. #3
    Originariamente inviato da badaze
    Non entra nella if xche la sintassi è scoretta. JS aspetta && o || tra due condizioni.
    ma quella in teoria è un'unica condizione :master:
    se devo controllare che tutte quelle variabili siano uguali come devo fare?

    te lo chiedo perché diversamente da così non saprei cosa fare.

    grazie!
    Talvolta anche una persona apparentemente inutile si rivela un abile samurai dalla forza di mille uomini, dimostrando di poter rinunciare alla vita e che il suo cuore si è completamente identificato con quello del suo padrone

  4. #4
    ho provato a fare così per tentare di fregare un pò la sintassi ma non ne ho ricavato nulla; eppure questa sintassi mi sembra corretta :master: infatti non mi restituisce nessun errore, come non me lo restituiva prima, l'unica cosa è che non entra nell'if:

    function guestForm(){
    var tot_isr = document.getElementById("tot_isr");
    var tot_vig = document.getElementById("tot_vig");
    var tot_bra = document.getElementById("tot_bra");
    var tot_gre = document.getElementById("tot_gre");
    var tot_lib = document.getElementById("tot_lib");
    var tot_tri = document.getElementById("tot_tri");
    var tot_mon = document.getElementById("tot_mon");
    var tot_ita = document.getElementById("tot_ita");

    tot_isr = parseInt(tot_isr.value, 10);
    tot_vig = parseInt(tot_vig.value, 10);
    tot_bra = parseInt(tot_bra.value, 10);
    tot_gre = parseInt(tot_gre.value, 10);
    tot_lib = parseInt(tot_lib.value, 10);
    tot_tri = parseInt(tot_tri.value, 10);
    tot_mon = parseInt(tot_mon.value, 10);
    tot_ita = parseInt(tot_ita.value, 10);
    if (!(tot_isr == tot_vig && tot_vig == tot_bra && tot_bra == tot_gre && tot_gre == tot_lib && tot_lib == tot_tri && tot_tri == tot_mon && tot_mon == tot_ita)){
    alert("controlla i dati");
    }
    }


    qualcuno mi aiuta?
    Talvolta anche una persona apparentemente inutile si rivela un abile samurai dalla forza di mille uomini, dimostrando di poter rinunciare alla vita e che il suo cuore si è completamente identificato con quello del suo padrone

  5. #5
    ho modificato la condizione così:
    if (!((tot_isr == tot_vig) && (tot_vig == tot_bra) && (tot_bra == tot_gre) && (tot_gre == tot_lib) && (tot_lib == tot_tri) && (tot_tri == tot_mon) && (tot_mon == tot_ita)))
    ma non funziona lo stesso.

    ho provato a mettere un else con un altro alert ma non entra nemmeno nell'else; com'è possibile che non entri nè nell'if nè nell'else? :master:

    la funzione ho controllato e viene eseguita, perché se al suo interno metto solo un alert me lo stampa, però con quel fantastico if/else non succede assolutamente nulla.
    sono disperato

    qualcuno ha idee del perché dello strano comportamento?o magari dove sbaglio?perché io proprio non riesco a capirlo.

    Talvolta anche una persona apparentemente inutile si rivela un abile samurai dalla forza di mille uomini, dimostrando di poter rinunciare alla vita e che il suo cuore si è completamente identificato con quello del suo padrone

  6. #6
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Ecco come puoi fare....

    codice:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <script language="JavaScript" type="text/javascript">
    <!--
    tot_isr = 10; 
    tot_vig = 10; 
    tot_bra = 10; 
    tot_gre = 10; 
    tot_lib = 10; 
    tot_tri = 10; 
    tot_mon = 1; 
    tot_ita = 10; 
    
    var arrVal = new Array();
    
    arrVal[arrVal.length] = tot_isr ; 
    arrVal[arrVal.length] = tot_vig ; 
    arrVal[arrVal.length] = tot_bra ; 
    arrVal[arrVal.length] = tot_gre ; 
    arrVal[arrVal.length] = tot_lib ; 
    arrVal[arrVal.length] = tot_tri ; 
    arrVal[arrVal.length] = tot_mon ; 
    arrVal[arrVal.length] = tot_ita ; 
    
    ok = true;
    for (i=0;i<arrVal.length;i++) {
     for (j=0;j<arrVal.length;j++) {
      if (arrVal[i] != arrVal[j]) {
    	 ok = false;
    	} // if (arrVal[i] != arrVal[j])
     } // for (j=0;j<arrVal.length;j++) 
    } // for (i=0;i<arrVal.length;i++) 
    alert(ok);
    //-->
    </script>
    
    </body>
    </html>

  7. #7
    codice:
    function guestForm(){
    	var tot_isr = document.getElementById("tot_isr");
    	var tot_vig = document.getElementById("tot_vig");
    	var tot_bra = document.getElementById("tot_bra");
    	var tot_gre = document.getElementById("tot_gre");
    	var tot_lib = document.getElementById("tot_lib");
    	var tot_tri = document.getElementById("tot_tri");
    	var tot_mon = document.getElementById("tot_mon");
    	var tot_ita = document.getElementById("tot_ita");
    	
    	tot_isr = parseInt(tot_isr.value, 10);
    	tot_vig = parseInt(tot_vig.value, 10);
    	tot_bra = parseInt(tot_bra.value, 10);
    	tot_gre = parseInt(tot_gre.value, 10);
    	tot_lib = parseInt(tot_lib.value, 10);
    	tot_tri = parseInt(tot_tri.value, 10);
    	tot_mon = parseInt(tot_mon.value, 10);
    	tot_ita = parseInt(tot_ita.value, 10);
    	
    	var arrVal = new Array();
    	arrVal[arrVal.length] = tot_isr ; 
    	arrVal[arrVal.length] = tot_vig ; 
    	arrVal[arrVal.length] = tot_bra ; 
    	arrVal[arrVal.length] = tot_gre ; 
    	arrVal[arrVal.length] = tot_lib ; 
    	arrVal[arrVal.length] = tot_tri ; 
    	arrVal[arrVal.length] = tot_mon ; 
    	arrVal[arrVal.length] = tot_ita ; 
    
    	ok = true;
    	for (i=0;i<arrVal.length;i++) {
    		for (j=0;j<arrVal.length;j++) {
    	  		if (arrVal[i] != arrVal[j]) {
    		 		ok = false;
    			} // if (arrVal[i] != arrVal[j])
    		} // for (j=0;j<arrVal.length;j++) 
    	} // for (i=0;i<arrVal.length;i++) 
    	alert(ok);
    
    }
    ho fatto così ma non funziona lo stesso, non mi scrive nessun alert
    Talvolta anche una persona apparentemente inutile si rivela un abile samurai dalla forza di mille uomini, dimostrando di poter rinunciare alla vita e che il suo cuore si è completamente identificato con quello del suo padrone

  8. #8
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Originariamente inviato da 13manuel84
    codice:
    function guestForm(){
    	var tot_isr = document.getElementById("tot_isr");
    	var tot_vig = document.getElementById("tot_vig");
    	var tot_bra = document.getElementById("tot_bra");
    	var tot_gre = document.getElementById("tot_gre");
    	var tot_lib = document.getElementById("tot_lib");
    	var tot_tri = document.getElementById("tot_tri");
    	var tot_mon = document.getElementById("tot_mon");
    	var tot_ita = document.getElementById("tot_ita");
    	
    	tot_isr = parseInt(tot_isr.value, 10);
    	tot_vig = parseInt(tot_vig.value, 10);
    	tot_bra = parseInt(tot_bra.value, 10);
    	tot_gre = parseInt(tot_gre.value, 10);
    	tot_lib = parseInt(tot_lib.value, 10);
    	tot_tri = parseInt(tot_tri.value, 10);
    	tot_mon = parseInt(tot_mon.value, 10);
    	tot_ita = parseInt(tot_ita.value, 10);
    	
    	var arrVal = new Array();
    	arrVal[arrVal.length] = tot_isr ; 
    	arrVal[arrVal.length] = tot_vig ; 
    	arrVal[arrVal.length] = tot_bra ; 
    	arrVal[arrVal.length] = tot_gre ; 
    	arrVal[arrVal.length] = tot_lib ; 
    	arrVal[arrVal.length] = tot_tri ; 
    	arrVal[arrVal.length] = tot_mon ; 
    	arrVal[arrVal.length] = tot_ita ; 
    
    	ok = true;
    	for (i=0;i<arrVal.length;i++) {
    		for (j=0;j<arrVal.length;j++) {
    	  		if (arrVal[i] != arrVal[j]) {
    		 		ok = false;
    			} // if (arrVal[i] != arrVal[j])
    		} // for (j=0;j<arrVal.length;j++) 
    	} // for (i=0;i<arrVal.length;i++) 
    	alert(ok);
    
    }
    ho fatto così ma non funziona lo stesso, non mi scrive nessun alert
    Sei sicuro che la funziona viene richiamata ?
    Hai tracciato i valori delle variabili?

  9. #9
    Originariamente inviato da badaze
    Sei sicuro che la funziona viene richiamata ?
    Hai tracciato i valori delle variabili?
    si la funzione viene richamata!l'avevo verificato anche prima. Perché mettendo un alert e basta questo mi viene segnalato. ma se metto tutta la funzione così come dovrebbe essere non funziona.

    le variabili vengono passate; perché facendo solo un alert con tutte le variabili mi vengono scritte
    Talvolta anche una persona apparentemente inutile si rivela un abile samurai dalla forza di mille uomini, dimostrando di poter rinunciare alla vita e che il suo cuore si è completamente identificato con quello del suo padrone

  10. #10
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Funziona benissimo. Ho preso i 4 primi campi

    codice:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>Untitled</title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function guestForm(){
    	var tot_isr = document.getElementById("tot_isr");
    	var tot_vig = document.getElementById("tot_vig");
    	var tot_bra = document.getElementById("tot_bra");
    	var tot_gre = document.getElementById("tot_gre");
    	
    	tot_isr = parseInt(tot_isr.value, 10);
    	tot_vig = parseInt(tot_vig.value, 10);
    	tot_bra = parseInt(tot_bra.value, 10);
    	tot_gre = parseInt(tot_gre.value, 10);
    	
    	var arrVal = new Array();
    	arrVal[arrVal.length] = tot_isr ; 
    	arrVal[arrVal.length] = tot_vig ; 
    	arrVal[arrVal.length] = tot_bra ; 
    	arrVal[arrVal.length] = tot_gre ; 
    
    	ok = true;
    	for (i=0;i<arrVal.length;i++) {
    		for (j=0;j<arrVal.length;j++) {
    	  		if (arrVal[i] != arrVal[j]) {
    		 		ok = false;
    			} // if (arrVal[i] != arrVal[j])
    		} // for (j=0;j<arrVal.length;j++) 
    	} // for (i=0;i<arrVal.length;i++) 
    	alert(ok);
    
    }
    //-->
    </script>
    
    </head>
    <body>
    <input type="text" id="tot_isr">
    
    <input type="text" id="tot_vig">
    
    <input type="text" id="tot_bra">
    
    <input type="text" id="tot_gre">
    
    <input type="button" onclick="guestForm()">
    </body>
    </html>

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.