Visualizzazione dei risultati da 1 a 4 su 4

Discussione: controllo form

  1. #1

    controllo form

    Ciao ragazzi, avendo il seguente codice, che mi controlla e che non ci siano campi vuoti e per questo non fa inviare il form all'utente finchè non li riempie, come si può aggiungere la funzione che il campo totale (total) in particolare non possa contenere un numero diverso da 10?
    grazie....

    <script type="text/javascript">

    function formCheck(formobj){

    var fieldRequired = Array ("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", "a16", "a17", "a18", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10", "b11", "b12", "b13", "b14", "b15", "b16", "b17", "b18", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16", "c17", "c18", "total1", "total2", "total1", "total2", "total3", "total4", "total5", "total6", "total7", "total8", "total9", "total10", "total11", "total12", "total13", "total14", "total15", "total16", "total17");

    var fieldDescription = Array ("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", "a16", "a17", "a18", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10", "b11", "b12", "b13", "b14", "b15", "b16", "b17", "b18", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16", "c17", "c18", "total1", "total2", "total1", "total2", "total3", "total4", "total5", "total6", "total7", "total8", "total9", "total10", "total11", "total12", "total13", "total14", "total15", "total16", "total17");


    var alertMsg = "Per favore completare tutti i campi";

    var l_Msg = alertMsg.length;

    for (var i = 0; i < fieldRequired.length; i++){
    var obj = formobj.elements[fieldRequired[i]];
    if (obj){
    if (obj.type == null){
    var blnchecked = false;
    for (var j = 0; j < obj.length; j++){
    if (obj[j].checked){
    blnchecked = true;
    }
    }
    if (!blnchecked){
    alertMsg += " "
    }
    continue;
    }

    switch(obj.type){
    case "select-one":
    if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
    alertMsg += " "
    }
    break;
    case "select-multiple":
    if (obj.selectedIndex == -1){
    alertMsg += " "
    }
    break;
    case "text":
    case "textarea":
    if (obj.value == "" || obj.value == null){
    alertMsg += " "
    }
    break;
    default:
    }
    }
    }

    if (alertMsg.length == l_Msg){
    return true;
    }else{
    alert(alertMsg);
    return false;
    }
    }

    </script>

  2. #2
    potrei usare anche?

    function calculate() {
    var f = document.calcform;
    var c1 = toNumber(f.c1.value);
    var b1 = toNumber(f.b1.value);
    var a1 = toNumber(f.a1.value);
    if (!isNaN(a1) && !isNaN(b1) && !isNaN(c1)) {
    f.total1.value = a1 + b1 + c1;
    if (f.total1.value != 10)
    if (f.total1.value != 0)
    alert("errore");
    if ((total1 = "10") || (total1 = "0"))
    alert("Il Totale è errato");
    document.calcform.f.c1.focus();
    return false;
    }

  3. #3
    qualcuno mi aiuta?

  4. #4

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.