Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    74

    il form nn viene convalidato

    salve
    ho scritto il mio primo codice in javascript, ma nn capisco come mai il form viene spedito senza che i controlli vengano effettuati

    posto il codice:


    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function Convalida() {
    var nome = document.Form.campo1.value;
    var cognome = document.Form.campo2.value;
    if (nome=='') {alert(“Campo obbligatorio!”)return false}
    if (cognome=='') {alert(“Campo obbligatorio!”)return false}
    return true;
    }
    //-->
    </script>

    </head>
    <body>

    <h1>JSP Page</h1>

    <form name="Form" method="post" action ="/index.jsp" onSubmit="return Convalida()">
    <input type="text" name="campo1" value="" />
    <input type="text" name="campo2" value="" />
    <input type="submit" value="ok" name="ok" />
    </form>

    </body>
    </html>

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    prova cosi:
    codice:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function Convalida() {
    var nome = document.Form.campo1.value;
    var cognome = document.Form.campo2.value;
    if (nome=='') {alert("Campo obbligatorio!");return false;}
    if (cognome=='') {alert("Campo obbligatorio!");return false;}
    }
    //-->
    </script>
    richiamato cosi:
    <form name="Form" method="post" action ="/index.jsp" onsubmit="return Convalida()">

    se l'errore persiste metti la pagina on-line.
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

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.