2016-10-21 2 views
1

안녕하세요 간단한 양식의 유효성을 검사하는 데 문제가 있습니다. 나는 Javascript에서 최고가 아니며 어디서 잘못 될지 확신 할 수 없다. 단순한 철자 오류이거나 내가 볼 수없는 코드 사이의 완전한 충돌 일 수 있습니다. 모든 도움을 주시면 감사하겠습니다. 코드의 큰 덩어리에 대해 유감스럽게 생각합니다. 모든 세부 사항을 확실히보고 싶었습니다.Javascript가 HTML의 양식을 확인하지 않습니다.

<!DOCTYPE html> 
<html> 
<head> 
<link rel = "stylesheet" 
    type = "text/css" 
    href = "Stylesheet.css" /> 
<title>Customer details form</title> 
<script src="gen_validatorv4.js" type="text/javascript"></script> 

<!-- ============================== My failed attempt to try and validate my form with Javascript ============================== --> 

<script> 
function check() { 
    document.getElementById("Agree").checked = true; 
} 
function uncheck() { 
    document.getElementById("Agree").checked = false; 
} 
</script> 
<center><img src= Images/HorizonHomePageTitle.png ALT="Horizon Bed and Breakfast Title"></center> 
</head> 
<body> 

<script> 
window.alert(Please enter data where * is assigned.); 
</script> 

<center><a href="XML/BudgetRooms.xml" target="_blank">Budget Rooms</a><center> 
<HR COLOR="blue" WIDTH="60%"> 
    <center><a href="XML/LuxuryRooms.xml" target="_blank">Luxury Rooms</a><center> 
<HR COLOR="blue" WIDTH="60%"> 
    <center><a href="Index.html" target="_blank">Home</a><center> 
<HR COLOR="blue" WIDTH="60%"> 
    <center><a href="https://www.visser.com.au/blog/generic-privacy-policy-for-australian-websites/" target="_blank">Our privacy policy</a><center> 
<HR COLOR="blue" WIDTH="60%"> 
    <center><a href="https://media.termsfeed.com/pdf/terms-and-conditions-template.pdf" target="_blank">Our terms of conditions</a><center> 
<HR COLOR="blue" WIDTH="60%"> 
    <center><a href=" http://www.blogtyrant.com/best-about-us-pages/" target="_blank">Our terms and conditions</a><center> 
<HR COLOR="blue" WIDTH="60%"> 
<center><a href="http://www.blogtyrant.com/best-contact-us-pages/" target="_blank">Contact us</a><center> 

<form id='CustomerDetailForm' action=""> 

     <!-- ============================== Fieldset 1 - includes personal information of clients ============================== --> 
     <fieldset> 
      <legend>Personal Information:</legend> 
      <hr class="form" /> 
       <label for="Full Name"><strong>Full Name:*</strong></label> 
       <input name="FullNm" type="text" size="20" id="FN" class="text"/> 

       <label for="Email"><strong>Email:</strong></label><br/> 
       <input name="Emil" type="text" size="20" id="EM" class="text"/> 

           <label for="Age"><strong>Input age if between 18 and 100:</strong></label> 
       <input name="Ages" type="text" size="20" id="AG" class="text"/> 

           <label for="select" class="choose"><strong>On what continent do you live?</strong></label> 
        <select id="select" name="select"> 
         <option value="1">Africa</option> 
         <option value="2">Europe</option> 
         <option value="3">Asia</option> 
         <option value="4">North Amrica</option> 
               <option value="5">South America</option> 
               <option value="6">Ausralia</option> 
             </select> 
     </fieldset> 
     <!-- ============================== Fieldset 2 - Includes further optional information from clients to help productivity ============================== --> 
     <fieldset> 
      <legend>Questions:</legend> 
      <hr class="form" /> 
       <label for="select2" class="choose">How long was your stay?</label><br /> 
        <select id="select" name="select2"> 
         <option value="7">Less than one week</option> 
         <option value="8">More than one week</option> 
         <option value="9">Months/years</option> 
        </select> 

       <label for="select3" class="choose">How many stars would you rate our BnB?</label><br /> 
        <select id="selectCon" name="select3"> 
         <option value="10">One star</option> 
         <option value="11">Two star</option> 
         <option value="12">Three star</option> 
         <option value="13">Four star</option> 
               <option value="14">Five star</option> 
             </select> 
       </fieldset> 
     <!-- ============================== Fieldset 3 - Holds the comments section, aggreement radio button, submit button and a date button for the client ============================== --> 
     <fieldset> 
      <legend>Further commetns:</legend> 
      <hr class="form" /> 
      <textarea name="message" id="message" cols="20" rows="10"></textarea><br /> 
      <label for="protection" class="spam-protection">Spam check: 1 + 1=</label><br /> 
      <input name="ochrana" type="text" id="protection" class="answer" /><br /> 

    Do you agree to our terms?*<br> 
    <input type="radio" name="Agreement" id="Agree">Agree<br> 

    <button onclick="formValidation()">SUBMIT</button> 

<script> 
function submitFunction() { 
    alert("Thankyou for your submission"); 
} 
</script> 

<script> 
    function formValidation() 
    { 
    var uname = document.registration.FullNm; 
    var uemail = document.registration.Emil; 
    var uage = document.registration.Ages; 
    var ucon = document.registration.select; 
    { 
    if(nameinput(FullName,2,25)) 
    { 
    if(emailval(uemail)) 
    { 
    if(agenum(ag)) 
    { 
    if(conselect(con)) 
    { 
    } 
    } 
    } 
    } 
    } 
    } 
    } 
    } 
    return false; 
    } 

    function nameinput(uname,2,25) 
    { 
    var uname_len = uname.value.length; 
    if (uname_len == 0 || uname_len >= 2 || uname_len < 25) 
    { 
    alert("Full Name is needed. Between "+2+" to "+25" characters.); 
    uname.focus(); 
    return false; 
    } 
    return true; 
    } 

function emailval(uemail,2,25) 
    { 
    var uemail_len = uemail.value.length; 
    if (uemail_len == 0 || uemail_len >= 2 || uemail_len < 30) 
    { 
    alert("Email is required."); 
    uemail.focus(); 
    return false; 
    } 
    return true; 
    } 

function agenum(uage,18,100) 
    { 
    var uage_len = uage.value.length; 
    if (uage_len == 0 || uage_len >= 18 || uage_len < 100) 
    { 
    alert("Age is required. Between 18 and 100."); 
    uage.focus(); 
    return false; 
    } 
    return true; 
    } 

function conselect(ucon) 
    { 
    if(ucon.value == "Default") 
    { 
    alert('Select your continent from the list'); 
    ucon.focus(); 
    return false; 
    } 
    else 
    { 
    return true; 
    } 
    } 
</script> 
</form> 

<button type="button" 
onclick="document.getElementById('date/time').innerHTML = Date()"> 
Display date and time.</button> 
<p id="date/time"></p> 

       </fieldset> 
</form> 
</body> 
</html> 
+1

나는 '맞춤법'의 맞춤법이 잘못 의도적 : – Turnip

+0

을 당신은 당신이 구문 오류가 있음을 볼 것입니다 들여 쓰기를 사용한 경우 바랍니다. 브라우저 콘솔에서 정확한 행을 가리 킵니다. – Turnip

+0

formValidation()에 중괄호가 있으면 안됩니다. 예를 들어. 112, 124 등 ... – Alessandro

답변

0
<!DOCTYPE html> 
<html> 
<head> 
    <link rel="stylesheet" type="text/css" href="Stylesheet.css" /> 
    <title>Customer details form</title> 
    <script src="gen_validatorv4.js" type="text/javascript"></script> 
    <!-- ============================== My failed attempt to try and validate my form with Javascript ============================== --> 
    <script type="text/javascript"> 
     function check() { 
      document.getElementById("Agree").checked = true; 
     } 
     function uncheck() { 
      document.getElementById("Agree").checked = false; 
     } 

     function formValidation() { 
      var uname = document.getElementById("FullNm"); 
      var uemail = document.getElementById("Email"); 
      var uage = document.getElementById("Ages"); 
      var ucon = document.getElementById("select1"); 

      if (nameInput(uname)) { 
       if (emailVal(uemail)) { 
        if (ageNum(uage)) { 
         if (conSelect(ucon)) { 
         } 
        } 
       } 
      } 
     } 

     function nameInput(uname) { 
      var uname_len = uname.value.length; 
      if (uname_len == 0 || uname_len <= 2 || uname_len > 25) { 
       alert("Full Name is needed. Between 2 to 25 characters."); 
       uname.focus(); 
       return false; 
      } 
      else { 
       return true; 
      } 
     } 

     function emailVal(uemail) { 
      var uemail_len = uemail.value.length; 
      if (uemail_len == 0) { 
       alert('Email is required'); 
       return false; 
      } 
      else { 
       return true; 
      } 
     } 

     function ageNum(uage) { 
      var age = uage.value; 
      if (age == 0 || age < 18 || age > 100) { 
       alert("Age is required. Between 18 and 100."); 
       uage.focus(); 
       return false; 
      } 
      else 
       return true; 
     } 


     function conSelect(ucon) { 
      if (ucon.value == 0) { 
       alert('Select your continent from the list'); 
       ucon.focus(); 
       return false; 
      } 
      else { 
       return true; 
      } 
     } 

    </script> 
    <center> 
     <img src="Images/HorizonHomePageTitle.png" alt="Horizon Bed and Breakfast Title"></center> 
</head> 
<body> 
    <center> 
     <a href="XML/BudgetRooms.xml" target="_blank">Budget Rooms</a><center> 
      <hr color="blue" width="60%"> 
      <center> 
       <a href="XML/LuxuryRooms.xml" target="_blank">Luxury Rooms</a><center> 
        <hr color="blue" width="60%"> 
        <center> 
         <a href="Index.html" target="_blank">Home</a><center> 
          <hr color="blue" width="60%"> 
          <center> 
           <a href="https://www.visser.com.au/blog/generic-privacy-policy-for-australian-websites/" 
            target="_blank">Our privacy policy</a><center> 
             <hr color="blue" width="60%"> 
             <center> 
              <a href="https://media.termsfeed.com/pdf/terms-and-conditions-template.pdf" target="_blank"> 
               Our terms of conditions</a><center> 
                <hr color="blue" width="60%"> 
                <center> 
                 <a href=" http://www.blogtyrant.com/best-about-us-pages/" target="_blank">Our terms 
                  and conditions</a><center> 
                   <hr color="blue" width="60%"> 
                   <center> 
                    <a href="http://www.blogtyrant.com/best-contact-us-pages/" target="_blank">Contact us</a><center> 
                     <form id='CustomerDetailForm' action=""> 
                     <!-- ============================== Fieldset 1 - includes personal information of clients ============================== --> 
                     <fieldset> 
                      <table> 
                       <tr> 
                        <td colspan="2"> 
                         <legend>Personal Information:</legend> 
                        </td> 
                       </tr> 
                       <tr> 
                        <td> 
                         <label for="Full Name"> 
                          <strong>Full Name:*</strong></label> 
                        </td> 
                        <td> 
                         <input id="FullNm" name="FullNm" type="text" size="20" class="text" /> 
                        </td> 
                       </tr> 
                       <tr> 
                        <td> 
                         <label for="Email"> 
                          <strong>Email:</strong></label><br /> 
                        </td> 
                        <td> 
                         <input id="Email" name="Email" type="text" size="20" class="text" /> 
                        </td> 
                       </tr> 
                       <tr> 
                        <td> 
                         <label for="Age"> 
                          <strong>Input age if between 18 and 100:</strong></label> 
                        </td> 
                        <td> 
                         <input name="Ages" type="text" size="20" id="Ages" class="text" /> 
                        </td> 
                       </tr> 
                       <tr> 
                        <td> 
                         <label for="select" class="choose"> 
                          <strong>On what continent do you live?</strong></label> 
                        </td> 
                        <td> 
                         <select id="select1" name="select"> 
                          <option value="0">Select</option> 
                          <option value="1">Africa</option> 
                          <option value="2">Europe</option> 
                          <option value="3">Asia</option> 
                          <option value="4">North Amrica</option> 
                          <option value="5">South America</option> 
                          <option value="6">Ausralia</option> 
                         </select> 
                        </td> 
                       </tr> 
                      </table> 
                     </fieldset> 
                     <!-- ============================== Fieldset 2 - Includes further optional information from clients to help productivity ============================== --> 
                     <fieldset> 
                      <legend>Questions:</legend> 
                      <hr class="form" /> 
                      <label for="select2" class="choose"> 
                       How long was your stay?</label><br /> 
                      <select id="select" name="select2"> 
                       <option value="7">Less than one week</option> 
                       <option value="8">More than one week</option> 
                       <option value="9">Months/years</option> 
                      </select> 
                      <label for="select3" class="choose"> 
                       How many stars would you rate our BnB?</label><br /> 
                      <select id="selectCon" name="select3"> 
                       <option value="10">One star</option> 
                       <option value="11">Two star</option> 
                       <option value="12">Three star</option> 
                       <option value="13">Four star</option> 
                       <option value="14">Five star</option> 
                      </select> 
                     </fieldset> 
                     <!-- ============================== Fieldset 3 - Holds the comments section, aggreement radio button, submit button and a date button for the client ============================== --> 
                     <fieldset> 
                      <legend>Further commetns:</legend> 
                      <hr class="form" /> 
                      <textarea name="message" id="message" cols="20" rows="10"></textarea><br /> 
                      <label for="protection" class="spam-protection"> 
                       Spam check: 1 + 1=</label><br /> 
                      <input name="ochrana" type="text" id="protection" class="answer" /><br /> 
                      Do you agree to our terms?*<br> 
                      <input type="radio" name="Agreement" id="Agree">Agree<br> 
                      <button onclick="formValidation();"> 
                       SUBMIT</button> 
                     </fieldset> 
                     </form> 
                     <script type="text/javascript"> 
                      function submitFunction() { 
                       alert("Thankyou for your submission"); 
                      } 
                     </script> 
                     <button type="button" onclick="document.getElementById('date/time').innerHTML = Date()"> 
                      Display date and time.</button> 
                     <p id="date/time"> 
                     </p> 
</body> 
</html> 
+0

지금 코드가 수정되었습니다. 확인해보십시오. –

관련 문제