[OCLUG-devel] JavaScript - An enhanced confirmation dialog box

Doug Jolley ddjolley at gmail.com
Fri Jul 22 08:34:45 PDT 2005


Thanks to all who rendered assistance with this problem.  I finally
got it resolved.  Basically the situation is that when the verify
function is called by the onsubmit event handler, that function just
runs from beginning to end without pausing for anything.  So, the
Accept button in the confirm window has to set a variable noting the
acceptance and then effect a click on the form's submit button which
causes the function to be re-run.

It turns out that the crux of my problem was this (and I'm not exactly
sure why I wasn't able to do it my way); but, I was trying to effect
the click on the form's submit button using the click() method of that
button.  Apparently what I needed to do was to use the submit() method
of the form.  As I say, I'm not exactly sure why my original way
didn't work; but, it doesn't.

So, again, thanks to all who contributed.  Just to get closure on this
issue, I'm appending my working script.  Here it is.  Thanks.
- - - - - - - - - - - - Cut Here - - - - - - - - - - 
<html>
 <head>
 <title>Test 2</title>
<script language="JavaScript">
<!--
function verify() {
var accept=false;
var isChecked=false;
var pCount=0;
for (var i=0; i<=document.roForm.partCount.length-1; i++) {
 if (document.roForm.partCount[i].checked == true)
   { isChecked=true;
     pCount=i+1;
     break }
 }
 if (isChecked == false)
   { alert("Please indicate the number of persons participating.");
return false }
if (document.roForm.Full_Name1.value.length == 0)
 { alert("Please complete the \"Name\" field for the first
participant."); return false }
if (pCount>=2 && document.roForm.Full_Name2.value.length == 0)
 { alert("Please complete the \"Name\" field for the second
participant."); return false }
if (pCount>=3 && document.roForm.Full_Name3.value.length == 0)
 { alert("Please complete the \"Name\" field for the third
participant."); return false }
if (pCount>=4 && document.roForm.Full_Name4.value.length == 0)
 { alert("Please complete the \"Name\" field for the fourth
participant."); return false }
var isChecked=false
for (var i=0; i<=document.roForm.Cabin_Category.length-1; i++) {
 if (document.roForm.Cabin_Category[i].checked == true)
   { isChecked=true
     break }
 }
 if (isChecked == false)
   { alert("Please select your cabin category type."); return false }
var isChecked=false
for (var i=0; i<=document.roForm.seating.length-1; i++) {
 if (document.roForm.seating[i].checked == true)
   { isChecked=true
     break }
 }
 if (isChecked == false)
   { alert("Please make your meal seating selection."); return false }
var isChecked=false
for (var i=0; i<=document.roForm.Rooming_Preference.length-1; i++) {
 if (document.roForm.Rooming_Preference[i].checked == true)
   { isChecked=true
     break }
 }
 if (isChecked == false)
   { alert("Please indicate your rooming preference."); return false }
 if (document.roForm.Rooming_Preference[2].checked == true &&
document.roForm.Roommate.value.length == 0)
   { alert("Please identify your roommate."); return false }
confirmWin=open("","confirmWindow","toolbar=1,location=1")
confirmWin.focus()
confirmWin.document.open()
confirmWin.document.write("My dog has fleas.")
confirmWin.document.write("<p><input type=\"button\" name=\"accept\"
value=\"Accept\"
onclick=\"accept=true;window.opener.document.roForm.submit();window.close()\"></p>")
confirmWin.document.write("<p><input type=\"button\" name=\"cancel\"
value=\"Cancel\" onclick=\"window.close()\"></p>")
confirmWin.document.close()
return accept
}
// -->
</script>
</head>
 <body bgcolor="#ffffff">
 <h2 align="center">Ron Oyer Test Form</h2>
 <form action="/dev/null" name="roForm" method="post" onsubmit="return
verify()">
  <table align="center">
   <tr>
     <td>Number of passengers in your cabin that are registering on
this form:</td>
     <td>
      <table><tr>
       <td><input type="radio" name="partCount" value="A">1</td>
       <td><input type="radio" name="partCount" value="B">2</td>
       <td><input type="radio" name="partCount" value="C">3</td>
       <td><input type="radio" name="partCount" value="D">4</td>
      </tr></table>
     </td>
   </tr>
   <tr><td>Name 1:</td><td><input type="text" name="Full_Name1"></td></tr>
   <tr><td>Name 2:</td><td><input type="text" name="Full_Name2"></td></tr>
   <tr><td>Name 3:</td><td><input type="text" name="Full_Name3"></td></tr>
   <tr><td>Name 4:</td><td><input type="text" name="Full_Name4"></td></tr>
   <tr>
     <td>Cabin Category:</td>
     <td>
      <table><tr>
       <td><input type="radio" name="Cabin_Category" value="A">A</td>
       <td><input type="radio" name="Cabin_Category" value="B">B</td>
       <td><input type="radio" name="Cabin_Category" value="C">C</td>
       <td><input type="radio" name="Cabin_Category" value="D">D</td>
      </tr></table>
     </td>
   </tr>
   <tr>
     <td>Meal Seating:</td>
     <td>
      <table><tr>
       <td><input type="radio" name="seating" value="First">First</td>
       <td><input type="radio" name="seating" value="Second">Second</td>
      </tr></table>
     </td>
   </tr>
   <tr>
     <td>Rooming Preference:</td>
     <td>
      <table><tr>
       <td><nobr><input type="radio" name="Rooming_Preference"
value="Alone">Alone</nobr></td>
       <td><nobr><input type="radio" name="Rooming_Preference"
value="Match">Match Me</nobr></td>
       <td><nobr><input type="radio" name="Rooming_Preference"
value="Share">Share with<input type="input"
name="Roommate"></nobr></td>
      </tr></table>
     </td>
   </tr>
  </table>
  <table align="center">
   <tr>
    <td><input type="reset"></td>
    <td><input type="submit" name="Submit"></td>
   </tr>
  </table>
 </form>
 </body>
</html>


More information about the OCLUG-devel mailing list