2017-07-20 5 views
0

Ma question est double. Tout d'abord, je n'arrive pas à comprendre comment faire pour que mon message confirme que la boîte de dialogue est ok et que l'annulation fonctionne correctement. L'affectation me demande d'exécuter le message, puis de valider mes informations, et si elle valide, d'alerter pour ok ou annuler. Je l'ai fait dans l'autre sens (valider ... message ... alerte), mais je ne suis pas sûr de savoir comment le faire. Deuxièmement, mon bouton de réinitialisation efface mes informations si je frappe ok ou annuler?? ????? Des idées?Confirmer la boîte de message Problème et bouton de réinitialisation Problème

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<!--Document Head--> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<!--Title Element--> 
<title>Greendale Community College</title> 
<!--Style Element--> 
<style type="text/css"> 
    body { 
     background-color: white; 
    } 

    h1 { 
     text-align: center; 
     font-family: Impact; 
     color: green; 
    } 

    p { 
     font-size: 36px; 
     color: green; 
    } 
</style> 
<!--Script Element--> 
<script type="text/javascript"> 
    /* <![CDATA[ */ 
    function submitRegistration() { 
     var fName = document.registration.firstName.value; 
     var lName = document.registration.lastName.value; 
     var cwid = document.registration.cwid.value; 
     var semester = document.registration.semester.value; 
     var course = document.registration.courses.value; 
     var section = document.registration.section.value; 
     var major = document.registration.needForMajor.value; 
     var semesterDisplay; 
     if (semester == "fall") 
      semesterDisplay = "Fall"; 
     if (semester == "spring") 
      semesterDisplay = "Spring"; 
     if (semester == "summer") 
      semesterDisplay = "Summer"; 
     var checkDisplay; 
     if (document.registration.needForMajor.checked == true) { 
      checkDisplay = "Course Needed For Major"; 
     } 
     else { 
      checkDisplay = ""; 
     } 
     window.confirm("Student Name: " + fName + " " + lName + " CWID: " + cwid + " Semester: " + semesterDisplay + " Course: " + course + " Section: " + section + " " + checkDisplay); 
     if (fName == "") { 
      window.alert("You must enter your first name!"); 
      return false; 
     } 
     if (isNaN(fName) == false) { 
      window.alert("Your First Name must be non-numeric values!"); 
      return false; 
     } 
     if (lName == "") { 
      window.alert("You must enter your last name!"); 
      return false; 
     } 
     if (isNaN(lName) == false) { 
      window.alert("Your Last Name must be non-numeric values!"); 
      return false; 
     } 
     if (cwid == "") { 
      window.alert("You must enter your cwid!"); 
      return false; 
     } 
     if (isNaN(cwid) == true) { 
      window.alert("Your CWID must be numeric values!"); 
      return false; 
     } 
     var validateSemester = false; 
     for (var i = 0; i < 3; ++i) { 
      if (document.registration.semester[i].checked == true) { 
       validateSemester = true; 
       break; 
      } 
     } 
     if (validateSemester != true) { 
      window.alert("You must select a Semester!"); 
      return false; 
     } 
     if (course == "") { 
      window.alert("You must select a Course!"); 
      return false; 
     } 
     if (section == "") { 
      window.alert("You must select a Section!"); 
      return false; 
     } 
     if (true) { 
      window.alert("You have been registered for your course!"); 
     } 
     else { 
      window.alert("Your registration has been canceled."); 
     } 
    } 
    function resetRegistration() { 
     var resetForm = window.confirm("Are you sure you want to reset the form?"); 
     if (resetForm == true) 
      return true; 
     return false; 
    } 
    /* ]]> */ 
</script> 
</head> 
<body> 
<!--Heading Element--> 
    <h1>Greendale Community College</h1> 
     <center><img src="greendale.jpg" alt="greendale" width="512" height="256" /></center> 
    <h2 align="center">Course Registration Page</h2> 
<form action="FormProcessor.html" name="registration" method="get" 
     onsubmit="submitRegistration();" 
     onreset="resetRegistration()"> 
    <h3>Student Information Form</h3> 
    <!--Student Information--> 
    First Name:<input type="text" name="firstName"><br> 
    Last Name:<input type="text" name="lastName"><br> 
    CWID:<input type="text" name="cwid"><br> 
    <h3>Semester</h3> 
    <h4>(choose a semester)</h4> 
    <!--Radio Buttons to Choose Semester--> 
    <input type="radio" name="semester" value="fall" /> Fall 2018 <br /> 
    <input type="radio" name="semester" value="spring" /> Spring 2018 <br /> 
    <input type="radio" name="semester" value="summer" /> Summer 2018 <br /> 
    <h3>Courses</h3> 
    <h4>(choose one course)</h4> 
    <table> 
     <!--Drop Down Box for Courses--> 
     <tr><td style="background:white;border:0">Courses:</td> 
     <tr> 
      <td> 
       <select name="courses" size="1"> 
        <option value=""></option> 
        <option value="CIS 110">Intro to CIS</option> 
        <option value="CIS 120">Application Prog I</option> 
        <option value="CIS 299">System Analysis I</option> 
        <option value="CIS 330">Web Programming I</option> 
        <option value="CIS 304">Cobol</option> 
       </select> 
      </td> 
     </tr> 
    </table> 
    <h3>Sections</h3> 
    <h4>(choose one section)</h4> 
    <table> 
     <tr><td style="background:white;border:0">Section Numbers:</td> 
     <tr> 
      <td> 
       <select name="section" multiple="multiple" size="5"> 
        <option value="001">CIS 110 001</option> 
        <option value="gw1">CIS110 GW1</option> 
        <option value="001">CIS 120 001</option> 
        <option value="gw1">CIS 120 GW1</option> 
        <option value="gw1">CIS 302 GW1</option> 
        <option value="001">CIS 304 001</option> 
        <option value="gw1">CIS 303 GW1</option> 
        <option value="001">CIS 321 001</option> 
        <option value="gw1">CIS 321 GW1</option> 
        <option value="gw1">CIS 322 GW1</option> 
       </select> 
       </td> 
      </tr> 
    </table> 
    <input type="checkbox" name="needForMajor" /> 
    Check if the course is required for your major!<br /> 
    <!--Submit and Reset Buttons Created--> 
    <input type="submit" name="submit" onsubmit="submitRegistration();" value="Submit"><br /> 
    <input type="reset" name="reset" onreset="resetRegistration();" value="Reset"> 
    </form> 
    </body> 
</html> 

Répondre

0

Essayez la solution ci-dessous. Ça devrait marcher.

<html xmlns="http://www.w3.org/1999/xhtml"> 
<!--Document Head--> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<!--Title Element--> 
<title>Greendale Community College</title> 
<!--Style Element--> 
<style type="text/css"> 
    body { 
     background-color: white; 
    } 

    h1 { 
     text-align: center; 
     font-family: Impact; 
     color: green; 
    } 

    p { 
     font-size: 36px; 
     color: green; 
    } 
</style> 
<!--Script Element--> 
<script type="text/javascript"> 
    /* <![CDATA[ */ 
    function submitRegistration() { 
     var fName = document.registration.firstName.value; 
     var lName = document.registration.lastName.value; 
     var cwid = document.registration.cwid.value; 
     var semester = document.registration.semester.value; 
     var course = document.registration.courses.value; 
     var section = document.registration.section.value; 
     var major = document.registration.needForMajor.value; 
     var semesterDisplay; 
     if (semester == "fall") 
      semesterDisplay = "Fall"; 
     if (semester == "spring") 
      semesterDisplay = "Spring"; 
     if (semester == "summer") 
      semesterDisplay = "Summer"; 
     var checkDisplay; 
     if (document.registration.needForMajor.checked == true) { 
      checkDisplay = "Course Needed For Major"; 
     } 
     else { 
      checkDisplay = ""; 
     } 

     if (fName == "") { 
      window.alert("You must enter your first name!"); 
      return false; 
     } 
     if (isNaN(fName) == false) { 
      window.alert("Your First Name must be non-numeric values!"); 
      return false; 
     } 
     if (lName == "") { 
      window.alert("You must enter your last name!"); 
      return false; 
     } 
     if (isNaN(lName) == false) { 
      window.alert("Your Last Name must be non-numeric values!"); 
      return false; 
     } 
     if (cwid == "") { 
      window.alert("You must enter your cwid!"); 
      return false; 
     } 
     if (isNaN(cwid) == true) { 
      window.alert("Your CWID must be numeric values!"); 
      return false; 
     } 
     var validateSemester = false; 
     for (var i = 0; i < 3; ++i) { 
      if (document.registration.semester[i].checked == true) { 
       validateSemester = true; 
       break; 
      } 
     } 
     if (validateSemester != true) { 
      window.alert("You must select a Semester!"); 
      return false; 
     } 
     if (course == "") { 
      window.alert("You must select a Course!"); 
      return false; 
     } 
     if (section == "") { 
      window.alert("You must select a Section!"); 
      return false; 
     } 
     var confirmation = window.confirm("Student Name: " + fName + " " + lName + " CWID: " + cwid + " Semester: " + semesterDisplay + " Course: " + course + " Section: " + section + " " + checkDisplay); 

     if (confirmation) { 
      window.alert("You have been registered for your course!"); 
      return true; 
     } 
     else { 
      window.alert("Your registration has been canceled."); 
      return false; 
     } 
    } 
    function resetRegistration() { 
     var resetForm = confirm("Are you sure you want to reset the form?"); 
     if (resetForm == true) 
      return true; 
     return false; 
    } 
    /* ]]> */ 
</script> 
</head> 
<body> 
<!--Heading Element--> 
    <h1>Greendale Community College</h1> 
     <center><img src="greendale.jpg" alt="greendale" width="512" height="256" /></center> 
    <h2 align="center">Course Registration Page</h2> 
<form action="FormProcessor.html" name="registration" method="get" onsubmit="return submitRegistration();" onreset="return resetRegistration();"> 
    <h3>Student Information Form</h3> 
    <!--Student Information--> 
    First Name:<input type="text" name="firstName"><br> 
    Last Name:<input type="text" name="lastName"><br> 
    CWID:<input type="text" name="cwid"><br> 
    <h3>Semester</h3> 
    <h4>(choose a semester)</h4> 
    <!--Radio Buttons to Choose Semester--> 
    <input type="radio" name="semester" value="fall" /> Fall 2018 <br /> 
    <input type="radio" name="semester" value="spring" /> Spring 2018 <br /> 
    <input type="radio" name="semester" value="summer" /> Summer 2018 <br /> 
    <h3>Courses</h3> 
    <h4>(choose one course)</h4> 
    <table> 
     <!--Drop Down Box for Courses--> 
     <tr><td style="background:white;border:0">Courses:</td> 
     <tr> 
      <td> 
       <select name="courses" size="1"> 
        <option value=""></option> 
        <option value="CIS 110">Intro to CIS</option> 
        <option value="CIS 120">Application Prog I</option> 
        <option value="CIS 299">System Analysis I</option> 
        <option value="CIS 330">Web Programming I</option> 
        <option value="CIS 304">Cobol</option> 
       </select> 
      </td> 
     </tr> 
    </table> 
    <h3>Sections</h3> 
    <h4>(choose one section)</h4> 
    <table> 
     <tr><td style="background:white;border:0">Section Numbers:</td> 
     <tr> 
      <td> 
       <select name="section" multiple="multiple" size="5"> 
        <option value="001">CIS 110 001</option> 
        <option value="gw1">CIS110 GW1</option> 
        <option value="001">CIS 120 001</option> 
        <option value="gw1">CIS 120 GW1</option> 
        <option value="gw1">CIS 302 GW1</option> 
        <option value="001">CIS 304 001</option> 
        <option value="gw1">CIS 303 GW1</option> 
        <option value="001">CIS 321 001</option> 
        <option value="gw1">CIS 321 GW1</option> 
        <option value="gw1">CIS 322 GW1</option> 
       </select> 
       </td> 
      </tr> 
    </table> 
    <input type="checkbox" name="needForMajor" /> 
    Check if the course is required for your major!<br /> 
    <!--Submit and Reset Buttons Created--> 
    <input type="submit" name="submit" value="Submit"><br /> 
    <input type="reset" name="reset" value="Reset"> 
    </form> 
    </body> 
</html> 
+0

Oui qui a travaillé pour la confirmation. Je ne pensais pas pouvoir le placer après, mais c'est logique maintenant. Des idées pour le bouton de réinitialisation? –

+0

La réinitialisation fonctionne également dans la solution fournie. Cela ne fonctionne pas pour vous? –

0

Je l'ai: j'oublié d'utiliser le retour:

<form action="FormProcessor.html" name="registration" method="get" 
     onsubmit="return submitRegistration();" 
     onreset="return resetRegistration()"> 

au lieu de:

<form action="FormProcessor.html" name="registration" method="get" 
     onsubmit="submitRegistration();" 
     onreset="resetRegistration()">