正确验证表单后如何显示表单详细信息?

时间:2019-03-19 06:32:50

标签: javascript html

我的问题是,如果我仅对表单执行验证,它将正确执行。但是,如果我编写了一个用于显示详细信息的显示功能,它将无法执行验证。如何验证显示在表单中的详细信息?

我在“提交”按钮上给出的内容正确吗?有什么变化吗?如何声明两个函数正确执行?

然后,当我显示详细信息时,我必须进行验证。请帮我配置一下。

<form name="RegForm" action="/submit.php" method="post">  
    <p>Name: <input id="name" type="text" size=65 name="Name"> </p><br>     
    <p>Dob:  <input id="dob" type="date"></p><br>  
    <p> Address: <input id="address" type="text" size=65 name="Address">  </p><br> 
    <p>E-mail Address: <input id="mail" type="text" size=65 name="EMail">  </p><br> 
    <p>Password: <input id="pass" type="text" size=65 name="Password"> </p><br> 
    <p>Telephone: <input id="phone" type="text" size=65 name="Telephone"> </p><br>   
    <p>Comments:  <textarea cols="55" id="Comment" name="Comment">  </textarea></p> 
    <p><input type="submit" value="send" name="Submit" onclick="Validate(); results(); return false"> 
</form> 

function Validate()                                    
{ 
    var name = document.forms["RegForm"]["Name"];               
    var email = document.forms["RegForm"]["EMail"];    
    var phone = document.forms["RegForm"]["Telephone"];  
    var what =  document.forms["RegForm"]["Subject"];  
    var password = document.forms["RegForm"]["Password"];  
    var address = document.forms["RegForm"]["Address"];  
   
    if (name.value == "")                                  
    { 
        window.alert("Please enter your name."); 
        name.focus(); 
        return false; 
    } 
   
    if (address.value == "")                               
    { 
        window.alert("Please enter your address."); 
        name.focus(); 
        return false; 
    } 
       
    if (email.value == "")                                   
    { 
        window.alert("Please enter a valid e-mail address."); 
        email.focus(); 
        return false; 
    } 
   
    if (email.value.indexOf("@", 0) < 0)                 
    { 
        window.alert("Please enter a valid e-mail address."); 
        email.focus(); 
        return false; 
    } 
   
    if (email.value.indexOf(".", 0) < 0)                 
    { 
        window.alert("Please enter a valid e-mail address."); 
        email.focus(); 
        return false; 
    } 
   
    if (phone.value == "")                           
    { 
        window.alert("Please enter your telephone number."); 
        phone.focus(); 
        return false; 
    } 
   
    if (password.value == "")                        
    { 
        window.alert("Please enter your password"); 
        password.focus(); 
        return flase; 
    } 
   
    if (what.selectedIndex < 1)                  
    { 
        alert("Please enter your course."); 
        what.focus(); 
        return false; 
    } 
   }
  function results()
    { 
        
    var name=document.getElementById('name').value;
        
        var dob=document.getElementById('dob').value;
        
        var address=document.getElementById('address').value;
     
         var email=document.getElementById('mail').value;
    
         var phone=document.getElementById('phone').value;

              document.write("<b>Submitted Successfully!!</b>");
              document.write("<b>here is your data.</b><br/>");
      
    
        document.write("Name :"+name+ " <br/>");
    
       
       
        document.write("DateOfBirth :"+dob+ " <br/>");
    


    
        document.write("Address:"+address+ " <br/>");

     
      document.write("Email :"+email+ " <br/>");


        document.write("Telephone: "+phone+ " <br/>");

    }



</script> 

如何配置?

0 个答案:

没有答案