2017-07-20 2 views
0

Meine Frage ist zweifach. Zuerst kann ich nicht herausfinden, wie ich meine Bestätigungsbox richtig machen und abbrechen kann, um korrekt zu funktionieren. Die Zuweisung fordert mich auf, die Nachricht auszuführen, dann validiere ich meine Informationen, und wenn sie gültig ist, warne sie auf OK oder löse sie ab. Ich habe es anders herum gemacht (validiere .... Nachricht .... Alarm), aber ich bin mir nicht sicher, wie ich das machen soll.Bestätigen Sie die Ausgabe und das Zurücksetzen des Nachrichtenfelds Ausgabe

Zweitens löscht meine Reset-Taste meine Informationen, ob ich ok oder Abbrechen bin ??? Irgendwelche Ideen?

<!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> 

Antwort

0

Versuchen Sie unter Lösung. Es sollte funktionieren.

<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

Ja, dass für die confirm gearbeitet. Ich dachte nicht, dass ich es nachher platzieren könnte, aber es macht jetzt Sinn. Irgendwelche Ideen für die Reset-Taste? –

+0

Reset funktioniert auch in der von mir bereitgestellten Lösung. Funktioniert es nicht für dich? –

0

Ich habe es: Ich habe vergessen Rückkehr zu verwenden:

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

statt:

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