Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    32

    Controllare un valore di un form

    Questo è ciò che devo fare.. inserisco il valore nome nel form. Questo valore prima di essere sottomesso deve essere controllato e deve contenere solo valori numerici compresi da 1 a 9..

    Codice html:


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=ISO-8859-15">
    <script type="text/javascript" src="check.js"></script>
    </head>
    <body>
    <form name="esame" action="" method="get" onSubmit="return check();">
    <label> NOME: <input name="nome" type="text" size="30" </label>
    <input type="submit" value="Submit" >
    <input type="reset" value="Reset">
    </form>
    </body>
    </html>


    Codice JS (sn una capra in Jscrip, vi avverto già in anticipo )

    function check ()
    {
    var value=document.nome;
    var i;
    for (i=0; i<30; i++)
    {
    if ((value(i)>0)&&(value(i)<10))
    return true;
    else
    {
    alert ("Nome errata");
    return false;
    }
    }}



    So di aver incasinato qualcosa... potete schiarirmi le idee? Grazie

  2. #2
    codice:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test eMail</title>
    <script type="text/javascript">
    function check(theForm) {
        var re = /^[1-9]+$/
        if (re.test(theForm.nome.value))
            return true;
        alert("Nome errata");
        return false;
    }
    </script>
    </head>
    <body>
    <form name="esame" action="" method="get" onsubmit="return check(this);">
    <label for="idNome"> NOME: </label><input id="idNome" name="nome" type="text" size="30" />
    <input type="submit" value="Submit" >
    <input type="reset" value="Reset">
    </form>
    </body>
    </html>
    Nota:
    La sintassi del tag <label> era errata: l'ho corretta

    HTH
    Zappa
    [PC:Presario 2515EU][Cpu:P4@2.3GHz][Ram: 512M][HDU:80G@5400 RPM]
    [Wireless:LinkSys][OS: Ubuntu 9.04 - Jaunty Jackalope]

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    32
    grazie..quindi avevo sbagliato anche l'html..


    arigrazie mille

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.