Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2013
    Messaggi
    41

    Javascript e verifica campi form

    Ho un problema con un javascript che verifica se i campi di un form sono compilati. con un input funziona mentre con un altro input con checkbox non va. Cosa sbaglio?
    Grazie

    Questo funziona
    codice:
    <div class="controls">
                                                <input class="span12" type="text" id="name" name="name" placeholder="* Nome-Cognome" />
                                                <div class="error left-align" id="err-name">Inserire nome.</div>
                                            </div>
    
    
    
    
     var name = $('input#name').val(); // get the value of the input field
            var error = false;
            if (name == "" || name == " ") {
                $('#err-name').show(500);
                $('#err-name').delay(4000);
                $('#err-name').animate({
                    height: 'toggle'
                }, 500, function () {
                    // Animation complete.
                });
                error = true; // change the error state to true
            }
    Questo invece no
    codice:
      <div class="controls">
    
        <input style="margin-top: 0px" type="checkbox" id="privacy"  name="privacy" value="Privacy Accettata" class="required">
        <label style="color: black; display: inline"> Autorizzo … </label> <div class="error left-align" id="err-privacy">Accettare privacy.</div>
    
      </div>
    
    
    
    
    
    
    var privacy = $('input#privacy').val(); // get the value of the input field
            var error = false;
            if (privacy == "" || privacy == " ") {
                $('#err-privacy').show(500);
                $('#err-privacy').delay(4000);
                $('#err-privacy').animate({
                    height: 'toggle'
                }, 500, function () {
                    // Animation complete.
                });
                error = true; // change the error state to true
            }

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2013
    Messaggi
    41
    Risolto. Ho usato

    codice:
    var checkBox = document.getElementById("privacy");
    	if (checkBox.checked == true){
        var error = false;
      }
    else  {
                $('#err-privacy').show(500);
                $('#err-privacy').delay(4000);
                $('#err-privacy').animate({
                    height: 'toggle'
                }, 500, function () {
                    // Animation complete.
                });
                error = true; // change the error state to true
            }

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