problems with dynamic forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brian.newman@wpafb.af.mil

    #1

    problems with dynamic forms

    I'm trying to use a layer inside a form to hide/reveal a part of the
    form, but my code doesn't seem to be working and I need some help
    debugging it.

    I'm not getting an error which has made it difficult to debug the code,
    but I am getting the alert ("break 4 in getStyleObject" ); which makes
    me think this is a browser compatability issue (I'm running IE 6.0).
    Anyway, the code follows
    function getStyleObject (objectId) {
    alert ("begin getSyleObject") ;
    if (document.getEl ementById && document.getEle mentById(object Id)) {
    alert ("break 1 in getStyleObject" );
    return document.getEle mentById(object Id).style;
    }
    else if (document.all && document.all(ob jectId)) {
    alert ("break 2 in getStyleObject" );
    return document.all(ob jectId).style;
    }
    else if (document.layer s && document.layers[objectId]) {
    alert ("break 3 in getStyleObject" );
    return document.layers[objectId];
    }
    else {
    alert ("break 4 in getStyleObject" );
    return false;
    }
    alert ("end getSyleObject") ;
    }
    function suspendSpouse(o bjectId) {
    alert ("begin suspendSpouse") ;
    var styleObject = getStyleObject (objectId);
    alert ("break 1 in suspendSpouse") ;
    if (styleObject) {
    styleObject.vis ibility = "hidden";
    alert ("break 2 in suspendSpouse") ;
    return true;
    }
    else {
    alert ("break 3 in suspendSpouse") ;
    return false;
    }
    alert ("end suspendSpouse") ;
    }

    function resumeSpouse (objectId) {
    alert ("check yes");
    alert ("begin resumeSpouse");
    var styleObject = getStyleObject (objectId);
    alert ("break 1 in resumeSpouse");
    if (styleObject) {
    styleObject.vis ibility = "visible";
    return true;
    }
    else {
    return false;
    }
    alert ("end suspendSpouse") ;
    }
    and the significant part of the form follows
    <tr>
    <td class="question ">Check if Spouse will come:</td>
    <td><input type="radio" name="Spouse_At tend" value="Yes"
    onClick="resume Spouse(spouseLa yer);">
    Yes
    <input type="radio" name="Spouse_At tend" value="No"
    onClick="suspen dSpouse(spouseL ayer);">
    No
    </td>
    </tr>
    <div id="spouseLayer " style="position :relative; ">
    <tr>
    <td class="question ">Spouse's First Name:</td>
    <td><input type="text" name="Spouse_Fi rst_Name"
    maxlength="30"> </td>
    </tr>
    <tr>
    <td class="question ">Spouse's Last Name:</td>
    <td><input type="text" name="Spouse_La st_Name"
    maxlength="30"> </td>
    </tr>
    <tr>
    <td class="question ">Spouse's Contact Email</td>
    <td><input type="text" name="Spouse_em ail" maxlength="70"> </td>
    </tr>
    <tr>
    <td class="question ">Spouse will require a vegetarian meal:</td>
    <td><input type="radio" name="Spouse_me al_veggie" value="Yes">
    Yes
    <input type="radio" name="Spouse_me al_veggie" value="No">
    No
    </td>
    </tr>
    </div>

  • BMR

    #2
    Re: problems with dynamic forms

    I'm just having problems with IE style property ;-) It works fine with
    Firefox. Which has a good debugger, you should try it to find out
    where's the problem.
    Anyway it's "document.a ll[objectId]" with brackets. But your problem is
    not there. Are you sure about objectId ? Or does it exist while you call
    getStyleObject( ) ?

    BMR

    brian.newman@wp afb.af.mil a écrit :[color=blue]
    > I'm trying to use a layer inside a form to hide/reveal a part of the
    > form, but my code doesn't seem to be working and I need some help
    > debugging it.
    >
    > I'm not getting an error which has made it difficult to debug the code,
    > but I am getting the alert ("break 4 in getStyleObject" ); which makes
    > me think this is a browser compatability issue (I'm running IE 6.0).
    > Anyway, the code follows
    > function getStyleObject (objectId) {
    > alert ("begin getSyleObject") ;
    > if (document.getEl ementById && document.getEle mentById(object Id)) {
    > alert ("break 1 in getStyleObject" );
    > return document.getEle mentById(object Id).style;
    > }
    > else if (document.all && document.all(ob jectId)) {
    > alert ("break 2 in getStyleObject" );
    > return document.all(ob jectId).style;
    > }
    > else if (document.layer s && document.layers[objectId]) {
    > alert ("break 3 in getStyleObject" );
    > return document.layers[objectId];
    > }
    > else {
    > alert ("break 4 in getStyleObject" );
    > return false;
    > }
    > alert ("end getSyleObject") ;
    > }
    > function suspendSpouse(o bjectId) {
    > alert ("begin suspendSpouse") ;
    > var styleObject = getStyleObject (objectId);
    > alert ("break 1 in suspendSpouse") ;
    > if (styleObject) {
    > styleObject.vis ibility = "hidden";
    > alert ("break 2 in suspendSpouse") ;
    > return true;
    > }
    > else {
    > alert ("break 3 in suspendSpouse") ;
    > return false;
    > }
    > alert ("end suspendSpouse") ;
    > }
    >
    > function resumeSpouse (objectId) {
    > alert ("check yes");
    > alert ("begin resumeSpouse");
    > var styleObject = getStyleObject (objectId);
    > alert ("break 1 in resumeSpouse");
    > if (styleObject) {
    > styleObject.vis ibility = "visible";
    > return true;
    > }
    > else {
    > return false;
    > }
    > alert ("end suspendSpouse") ;
    > }
    > and the significant part of the form follows
    > <tr>
    > <td class="question ">Check if Spouse will come:</td>
    > <td><input type="radio" name="Spouse_At tend" value="Yes"
    > onClick="resume Spouse(spouseLa yer);">
    > Yes
    > <input type="radio" name="Spouse_At tend" value="No"
    > onClick="suspen dSpouse(spouseL ayer);">
    > No
    > </td>
    > </tr>
    > <div id="spouseLayer " style="position :relative; ">
    > <tr>
    > <td class="question ">Spouse's First Name:</td>
    > <td><input type="text" name="Spouse_Fi rst_Name"
    > maxlength="30"> </td>
    > </tr>
    > <tr>
    > <td class="question ">Spouse's Last Name:</td>
    > <td><input type="text" name="Spouse_La st_Name"
    > maxlength="30"> </td>
    > </tr>
    > <tr>
    > <td class="question ">Spouse's Contact Email</td>
    > <td><input type="text" name="Spouse_em ail" maxlength="70"> </td>
    > </tr>
    > <tr>
    > <td class="question ">Spouse will require a vegetarian meal:</td>
    > <td><input type="radio" name="Spouse_me al_veggie" value="Yes">
    > Yes
    > <input type="radio" name="Spouse_me al_veggie" value="No">
    > No
    > </td>
    > </tr>
    > </div>
    >[/color]

    Comment

    • Lee

      #3
      Re: problems with dynamic forms

      brian.newman@wp afb.af.mil said:[color=blue]
      >
      >I'm trying to use a layer inside a form to hide/reveal a part of the
      >form, but my code doesn't seem to be working and I need some help
      >debugging it.
      >
      >I'm not getting an error which has made it difficult to debug the code,
      >but I am getting the alert ("break 4 in getStyleObject" ); which makes
      >me think this is a browser compatability issue (I'm running IE 6.0).
      >Anyway, the code follows[/color]

      Your code would be MUCH easier to read if you used any of
      the standard indentation schemes.

      [color=blue]
      >function getStyleObject (objectId) {[/color]
      [color=blue]
      >onClick="resum eSpouse(spouseL ayer);">[/color]

      Your code is expecting an objectId that can be passed to
      getElementById, but you're passing a global reference to the div,
      instead. Put single quotes around 'spouseLayer' (in both onclick
      handlers).

      Comment

      • brian.newman@wpafb.af.mil

        #4
        Re: problems with dynamic forms

        I took your advice and ran it in Firefox. I got the error "spouseLaye r
        is not defined".
        That doesn't shed much light on the problem. spouseLayer is defined as
        the name of the div.

        Comment

        • Mick White

          #5
          Re: problems with dynamic forms

          brian.newman@wp afb.af.mil wrote:[color=blue]
          > I'm trying to use a layer inside a form to hide/reveal a part of the
          > form, but my code doesn't seem to be working and I need some help
          > debugging it.[/color]

          [snip]

          [color=blue]
          > <td><input type="radio" name="Spouse_At tend" value="Yes"
          > onClick="resume Spouse(spouseLa yer);">
          > Yes
          > <input type="radio" name="Spouse_At tend" value="No"
          > onClick="suspen dSpouse(spouseL ayer);">[/color]


          ....
          onClick="resume Spouse('spouseL ayer');">Yes
          <input type="radio" name="Spouse_At tend" value="No"
          onClick="suspen dSpouse('spouse Layer');">
          ....

          The function is expecting a String, no?
          Mick

          Comment

          • Michael Winter

            #6
            Re: problems with dynamic forms

            On 24 Jan 2005 10:50:34 -0800, <brian.newman@w pafb.af.mil> wrote:
            [color=blue]
            > spouseLayer is defined as the name of the div.[/color]

            That doesn't "define" anything. See
            <URL:http://jibbering.com/faq/#FAQ4_41>. Besides, even if passing an
            object reference via that approach does work, it's not what the function
            expects (as others have pointed out).

            Mike

            --
            Michael Winter
            Replace ".invalid" with ".uk" to reply by e-mail.

            Comment

            • brian.newman@wpafb.af.mil

              #7
              Re: problems with dynamic forms

              thanks, I missed that
              but now that I made that change, it still won't make the layer
              disappear

              Comment

              • Lee

                #8
                Re: problems with dynamic forms

                brian.newman@wp afb.af.mil said:[color=blue]
                >
                >I took your advice and ran it in Firefox. I got the error "spouseLaye r
                >is not defined".
                >That doesn't shed much light on the problem. spouseLayer is defined as
                >the name of the div.[/color]

                Making "spouseLaye r" the id attribute of an element doesn't define a
                variable by that name.

                Comment

                • brian.newman@wpafb.af.mil

                  #9
                  Re: problems with dynamic forms

                  Okay, but I cleaned up my code a little bit and am still having trouble
                  I guess I'm missing something really basic
                  Anyway, here's the current code
                  function suspendSpouse(o bjectId) {
                  var styleObject = document.getEle mentById(object Id).style;
                  if (styleObject) {
                  styleObject.vis ibility = "hidden";
                  return true;
                  }
                  else {
                  return false;
                  }
                  }

                  function resumeSpouse (objectId) {
                  var styleObject = document.getEle mentById(object Id).style;
                  if (styleObject) {
                  styleObject.vis ibility = "visible";
                  return true;
                  }
                  else {
                  return false;
                  }
                  }
                  ..
                  ..
                  ..
                  <tr>
                  <td class="question ">Check if Spouse will come:</td>
                  <td><input type="radio" name="Spouse_At tend" value="Yes"
                  onClick="resume Spouse('spouseL ayer');">
                  Yes
                  <input type="radio" name="Spouse_At tend" value="No"
                  onClick="suspen dSpouse('spouse Layer');">
                  No
                  </td>
                  </tr>

                  Comment

                  • Lee

                    #10
                    Re: problems with dynamic forms

                    brian.newman@wp afb.af.mil said:[color=blue]
                    >
                    >Okay, but I cleaned up my code a little bit and am still having trouble
                    >I guess I'm missing something really basic[/color]


                    The following works in IE and Firefox.
                    I didn't change the script significantly.
                    Since you were discarding the returned values, I removed them,
                    and I formatted the code so that I can read it.

                    My guess is that there's a problem with your HTML.


                    <html>
                    <head>
                    <script type="text/javascript">
                    function suspendSpouse(o bjectId) {
                    var styleObject = document.getEle mentById(object Id).style;
                    if (styleObject) {
                    styleObject.vis ibility = "hidden";
                    }
                    }

                    function resumeSpouse (objectId) {
                    var styleObject = document.getEle mentById(object Id).style;
                    if (styleObject) {
                    styleObject.vis ibility = "visible";
                    }
                    }
                    </script>
                    </head>
                    <body>
                    <form>
                    Check if Spouse will come:
                    <br>
                    <input type="radio"
                    name="Spouse_At tend"
                    value="Yes"
                    checked="checke d"
                    onclick="resume Spouse('spouseL ayer');"> Yes
                    <br>
                    <input type="radio"
                    name="Spouse_At tend"
                    value="No"
                    onclick="suspen dSpouse('spouse Layer');"> No
                    <br>
                    <div id="spouseLayer ">SpouseLay er</div>
                    </form>
                    </body>
                    </html>

                    Comment

                    • brian.newman@wpafb.af.mil

                      #11
                      Re: problems with dynamic forms

                      I used your script and the page still didn't work as hoped. So, I must
                      have a problem with my html.
                      I know I've already taken a great deal of your time, but if you don't
                      mind, I really need some help here.
                      My complete page is, now, as follows

                      <%@ Language=VBScri pt %>
                      <% Option Explicit %>

                      <!--#include file = "DatabaseConnec t.asp"-->
                      <!--#include file = "adovbs.inc "-->

                      <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN">
                      <html>
                      <head>
                      <title>Air Force Material Command Squadron Commanders' and Directors'
                      Course Registration Page </title>
                      <meta http-equiv="Content-Type" content="text/html;
                      charset=iso-8859-1">
                      <style type="text/css">
                      body {
                      background: blue;
                      }
                      table {
                      width: 95%;
                      border: "0";
                      align: "center";
                      }
                      img {
                      width: "128";
                      height: "128";
                      align: "center";
                      }
                      h1 {
                      font-size: 24px;
                      font-weight: bold;
                      }
                      h2 {
                      font-size: 18px;
                      }
                      p {
                      font-family: "Times New Roman", Times, serif;
                      font-size: 14px;
                      }
                      hr {
                      width: "100%";
                      size: = "1";
                      noshade;
                      }
                      td.question {
                      width: "279";
                      align: "right";
                      }
                      td.ContactInfo {
                      font-color:"white";
                      font-size:+1;
                      }
                      td.linebreak {
                      colspan: "2";
                      }

                      </style>
                      <script type="text/javascript" language="javas cript">
                      function DisplayErrors() {
                      if (document.enrol l.coursedate.va lue=="") alert ("Please enter a
                      coursedate");
                      if (document.enrol l.rank.value==" ") alert ("Please enter a rank");
                      if ((isValidName(d ocument.enroll. firstname.value ))==false) alert
                      ("Please enter your first name");
                      if ((isValidName(d ocument.enroll. middleinitial.v alue))==false) alert
                      ("Please enter your middle initial");
                      if ((isValidName(d ocument.enroll. lastname.value) )==false) alert
                      ("Please enter your last name");
                      if ((isValidDate(d ocument.enroll. dateRank.value) )==false) alert
                      ("Please enter valid date of rank in form mm/dd/yyyy");
                      if (document.enrol l.projected_uni t.value=="") alert ("Please enter
                      your projected unit");
                      if (document.enrol l.projected_bas e.value=="") alert ("Please enter
                      your projected base");
                      if (isValidPhone(d ocument.enroll. projected_phone .value)==false)
                      alert ("Please enter a valid projected phone number in the form
                      xxx-xxx-xxxx");
                      if (isValidDate(do cument.enroll.C hange_com_date. value)==false) alert
                      ("Please enter a valid date for the change of command in the form
                      mm/dd/yyyy");
                      if (isValidEmail(d ocument.enroll. Current_email.v alue)==false) alert
                      ("Please enter your current email address");
                      if (isValidEmail(d ocument.enroll. Transit_Email.v alue)==false) alert
                      ("Please enter a valid transit email");


                      } // end DisplayErrors function

                      function ValidateForm()
                      {
                      alert ("form validation started");
                      var passCheck = false;
                      if ((document.enro ll.coursedate.v alue!=="") &&
                      (document.enrol l.rank.value!== "") &&
                      (document.enrol l.firstname.val ue!=="") &&
                      (document.enrol l.lastname.valu e!=="") &&
                      (isValidDate(do cument.enroll.r ankdate.value)! ==false) &&
                      (document.enrol l.projected_uni t.value!=="") &&
                      (document.enrol l.projected_bas e.value!=="") &&
                      (isValidPhone(d ocument.enroll. projected_phone .value)!==false ) &&
                      (isValidDate(do cument.enroll.c hange_com_date. value)!==false) &&
                      (isValidEmail(d ocument.enroll. current_email.v alue)!== false) &&
                      (isValidEmail(d ocument.enroll. Transit_Email.v alue)!==false) &&
                      (isValidPhone(d ocument.enroll. Transit_Phone.v alue)!==false) &&
                      (document.enrol l.Current_Base. value!=="") &&
                      (document.enrol l.Current_Unit. value!=="") &&
                      (isValidPhone(d ocument.enroll. Current_DSN.val ue)!==false) &&
                      (document.enrol l.Spouse_First_ Name.value!=="" ) &&
                      (document.enrol l.Spouse_Last_N ame.value!=="") &&
                      (isValidEmail(d ocument.enroll. Spouse_Email)!= =false))
                      {
                      passCheck = true;
                      }
                      if (passCheck==fal se) DisplayErrors() ;
                      return passCheck;
                      } // end isFormValid function



                      function isValidDate (testDate) {
                      var invalidDate = true;
                      //alert ("isValidDat e break 1");
                      if (testDate.lengt h!==8)
                      {
                      alert ("date is not of expected length");
                      return false;
                      }
                      datePart = testDate.slice( 0,1);
                      if (cint(datePart) < 1) OR (cint(datePart) > 12)
                      {
                      alert ("month is not in expected range");
                      return false;
                      }
                      datePart = testDate.slice (2,3);
                      if (cint(datePart < 1)) OR (cint(datePart) > 12)
                      {
                      alert ("day is not in expected range");
                      return false;
                      }
                      datePart = testDate.slice (4,7);
                      if (cint(datePart) < 1950) OR (cint(datePart) > 2050)
                      {
                      alert ("year is not in expected range");
                      return false;
                      }
                      return true;
                      } // end isValidDate function

                      function isValidName (testName) {
                      var myRegExp = /[A-Z][a-z]{1,29}/;
                      //alert (myRegExp.test( testName));
                      return myRegExp.test(t estName);
                      } // end isValidName function

                      function isValidPhone (testPhone) {
                      var myRegExp = /[1-9][0-9]{2}-[0-9]{4}/;
                      return myRegExp.test(t estPhone);

                      } // end isValidPhone function

                      function isValidEmail (testEmail) {
                      var myRegExp =
                      /[a-z0-9.]{1,40}@[a-z0-9.]{4,65}.(com|net |org|info|biz|([a-z]{2,3}.[a-z]{2}))/;
                      return myRegExp.test(t estEmail)
                      } // end isValidEmail function

                      function getStyleObject (objectId) {
                      //alert ("begin getSyleObject") ;
                      //if (document.getEl ementById && document.getEle mentById(object Id))
                      {
                      //alert ("break 1 in getStyleObject" );
                      return document.getEle mentById(object Id).style;
                      //}
                      //else if (document.all && document.all(ob jectId)) {
                      //alert ("break 2 in getStyleObject" );
                      //return document.all(ob jectId).style;
                      //}
                      //else if (document.layer s && document.layers[objectId]) {
                      //alert ("break 3 in getStyleObject" );
                      //return document.layers[objectId];
                      //}
                      //else {
                      //alert ("break 4 in getStyleObject" );
                      //return false;
                      //}
                      //alert ("end getSyleObject") ;
                      }
                      function suspendSpouse(o bjectId) {
                      //alert ("begin suspendSpouse") ;
                      //var styleObject = getStyleObject (objectId);
                      var styleObject = document.getEle mentById(object Id).style;
                      //alert ("break 1 in suspendSpouse") ;
                      if (styleObject) {
                      //alert ("styleObject.v isibility = "+styleObject.v isibility);
                      styleObject.vis ibility = "hidden";
                      //alert ("styleObject.v isibility = "+styleObject.v isibility);
                      //alert ("break 2 in suspendSpouse") ;
                      //return true;
                      }
                      //else {
                      //alert ("break 3 in suspendSpouse") ;
                      //return false;
                      //}
                      //alert ("end suspendSpouse") ;
                      }

                      function resumeSpouse (objectId) {
                      //alert ("check yes");
                      //alert ("begin resumeSpouse");
                      //var styleObject = getStyleObject (objectId);
                      var styleObject = document.getEle mentById(object Id).style;
                      //alert ("break 1 in resumeSpouse");
                      if (styleObject) {
                      styleObject.vis ibility = "visible";
                      //return true;
                      }
                      //else {
                      //return false;
                      //}
                      //alert ("end suspendSpouse") ;
                      }



                      </script>
                      </head>
                      <body>
                      <table>
                      <tr>
                      <td><img src="afmc.gif" alt="HQ AFMC shield"></td>
                      </tr>
                      <tr>
                      <td><h1>Air Force Materiel Command</h1></td>
                      </tr>
                      <tr>
                      <td><h1>Squadro n Commanders' and Directors' Course</h1></td>
                      </tr>
                      <tr>
                      <td><h1>Registr ation Page</h1></td>
                      </tr>
                      <tr>
                      <td><p>(Use the &quot;TAB&qu ot; key or mouse button to move to the
                      next cell entry. &quot;ENTER&quo t; key will submit registration
                      pre-maturely<p></td>
                      </tr>
                      <tr>
                      <td class="linebrea k"><hr></td>
                      </tr>
                      <tr>
                      <td><h2>Attende e Information:</h2></td>
                      </tr>
                      <tr>
                      <td>
                      <form name="enroll" method="post" onsubmit="retur n ValidateForm()"
                      action="/sqccform/sqccform2.asp">
                      <table>
                      <tr>
                      <td class="question ">Requested Course Date:</td>
                      <td><select name="coursedat e">
                      <option value="">Select a Course Date
                      <option value="March 14-18">March 14-18
                      <option value="May 23-27">May 23-27
                      <option value="July 11-15">July 11-15
                      <option value="Aug 29-Sept 2">Aug 29-Sept 2
                      <option value="Sep 26-30">Sept 26-30
                      </select>
                      </td>
                      </tr>
                      <tr>
                      <td class="question ">Select Rank/Civ Paygrade:</td>
                      <td><select name="rank">
                      <option value="">Select Rank/Civ Paygrade
                      <option value="Capt">Ca pt
                      <option value="Maj">Maj
                      <option value="LtCol">L t Col
                      <option value="Col">Col
                      <option value="GS-12">GS-12
                      <option value="GS-13">GS-13
                      <option value="GS-14">GS-14
                      <option value="GS-15">GS-15
                      </select>
                      </td>
                      </tr>
                      <tr>
                      <td class="question ">First Name:</td>
                      <td><input type="text" name="firstname " maxlength="30"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Middle Initial:</td>
                      <td><input type="text" name="middleini tial" maxlength="1"></td>
                      </tr>
                      <tr>
                      <td class="question ">Last Name:</td>
                      <td><input type="text" name="lastname" maxlength="30"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Go By Name:</td>
                      <td><input type="text" name="gobyname" maxlength="30"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Date of Rank:</td>
                      <td><input type="text" name="dateRank" maxlength="8"></td>
                      </tr>
                      <tr>
                      <td class="question ">Projected Unit</td>
                      <td><select name="projected _unit">
                      <option value="">Select a Unit
                      <%
                      dim objRs
                      set objRs=Server.Cr eateObject("ADO DB.Recordset")
                      objRs.Open "squadlist" , objConn
                      do while NOT objRs.EOF
                      %>
                      <option
                      value="<%=objRs ("squadname")%> "><%=objRs("squ adname")%>
                      <%
                      objRs.MoveNext
                      loop
                      objRs.Close
                      set objRs = Nothing
                      objConn.Close
                      set objConn = Nothing
                      %>
                      </select>
                      </td>
                      </tr>
                      <tr>
                      <td class="question ">Projected Base:</td>
                      <td><input type="text" name="projected _base"
                      maxlength="50"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Projected DSN Phone:</td>
                      <td><input type="text" name="projected _phone"
                      maxlength="12"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Change of Command:</td>
                      <td><input type="text" name="Change_co m_date"
                      maxlength="8"></td>
                      </tr>
                      <tr>
                      <td class="question ">Current Email Address:</td>
                      <td><input type="text" name="Current_e mail" maxlength="70"> </td>
                      </tr>
                      <tr>
                      <td class="question ">In Transit E-mail Address:</td>
                      <td><input type="text" name="Transit_E mail" maxlength="70"> </td>
                      </tr>
                      <tr>
                      <td class="question ">In Transit Phone Number:</td>
                      <td><input type="text" name="Transit_P hone" maxlength="12"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Current Base:</td>
                      <td><select name="current_b ase">
                      </select>
                      </td>
                      </tr>
                      <tr>
                      <td class="question ">Current Unit:</td>
                      <td><input type="text" name="current_u nit" maxlength="50"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Current DSN Phone:</td>
                      <td><input type="text" name="current_d sn" maxlength="12"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Vegetaria n Meal Required:</td>
                      <td><input type="radio" name="Primary_V eggie" value="Yes">
                      Yes
                      <input type="radio" name="Primary_V eggie" value="No">
                      No
                      </td>
                      </tr>
                      <tr>
                      <td class="question ">Check if Spouse will come:</td>
                      <td><input type="radio" name="Spouse_At tend" value="Yes"
                      onclick="resume Spouse('spouseL ayer');"> Yes
                      <input type="radio" name="Spouse_At tend" value="No"
                      checked="checke d" onclick="suspen dSpouse('spouse Layer');"> No
                      </td>
                      </tr>
                      <div id="spouseLayer ">
                      <tr>
                      <td class="question ">Spouse's First Name:</td>
                      <td><input type="text" name="Spouse_Fi rst_Name"
                      maxlength="30"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Spouse's Last Name:</td>
                      <td><input type="text" name="Spouse_La st_Name"
                      maxlength="30"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Spouse's Contact Email</td>
                      <td><input type="text" name="Spouse_em ail" maxlength="70"> </td>
                      </tr>
                      <tr>
                      <td class="question ">Spouse will require a vegetarian meal:</td>
                      <td><input type="radio" name="Spouse_me al_veggie" value="Yes">
                      Yes
                      <input type="radio" name="Spouse_me al_veggie" value="No">
                      No
                      </td>
                      </tr>
                      </div>
                      </table>
                      <tr>
                      <td class="linebrea k"><hr></td>
                      </tr>
                      <table>
                      <tr>
                      <td><input type=submit value="Submit"> </td>
                      <td><input type="reset" value="Clear Form and Start Over"></td>
                      </tr>
                      </table>
                      </form>
                      </td>
                      </tr>
                      <tr>
                      <td class="ContactI nfo">Questions ? Comments? Please call Capt. Dain
                      Klein at DSN: 787-2125<td>
                      </tr>
                      </table>
                      </body>
                      </html>

                      Comment

                      • Dr John Stockton

                        #12
                        Re: problems with dynamic forms

                        JRS: In article <1106659586.444 776.34160@f14g2 000cwb.googlegr oups.com>,
                        dated Tue, 25 Jan 2005 05:26:26, seen in news:comp.lang. javascript,
                        brian.newman@wp afb.af.mil posted :
                        [color=blue]
                        ><title>Air Force Material Command Squadron Commanders' and Directors'
                        >Course Registration Page </title>[/color]

                        A thoughtful and internationally-sensitive author would have indicated
                        which Air Force is being referred to.

                        [color=blue]
                        ><style type="text/css">[/color]

                        Forcing the sizes of fonts and suchlike is not considered good practice.
                        It is possible that you do not, in your application, need to allow for
                        those with sub-standard vision; but 14-point for ordinary text is too
                        large to suit me.
                        [color=blue]
                        >p {
                        >font-family: "Times New Roman", Times, serif;
                        >font-size: 14px;
                        >}[/color]

                        [color=blue]
                        ><script type="text/javascript" language="javas cript">[/color]
                        attribute not required
                        [color=blue]
                        >function DisplayErrors() {
                        >if (document.enrol l.coursedate.va lue=="") alert ("Please enter a
                        >coursedate") ;[/color]

                        If you want your code to be readable in News, do not let your posting
                        agent break lines. A good craftsman chooses good tools.

                        [color=blue]
                        >if ((isValidName(d ocument.enroll. firstname.value ))==false) alert
                        >("Please enter your first name");[/color]

                        ... == false is not needed; use !... .

                        Does it matter that some people put family name first, or does your
                        organisation not allow that?

                        [color=blue]
                        >function ValidateForm()
                        >{
                        >alert ("form validation started");[/color]


                        Code should be indented to show intended structure; you have chosen a
                        badly-designed posting agent which damages readability. A good
                        craftsman chooses good tools.


                        (isValidEmail(d ocument.enroll. Spouse_Email)!= =false))

                        That's an interesting operator to choose.

                        [color=blue]
                        >function isValidDate (testDate) {
                        >var invalidDate = true;
                        >//alert ("isValidDat e break 1");
                        >if (testDate.lengt h!==8)
                        >{
                        >alert ("date is not of expected length");
                        >return false;
                        >}
                        >datePart = testDate.slice( 0,1);
                        >if (cint(datePart) < 1) OR (cint(datePart) > 12)
                        >{
                        >alert ("month is not in expected range");
                        >return false;
                        >}
                        >datePart = testDate.slice (2,3);
                        >if (cint(datePart < 1)) OR (cint(datePart) > 12)
                        >{
                        >alert ("day is not in expected range");
                        >return false;
                        >}
                        >datePart = testDate.slice (4,7);
                        >if (cint(datePart) < 1950) OR (cint(datePart) > 2050)
                        >{
                        >alert ("year is not in expected range");
                        >return false;
                        >}
                        >return true;
                        >} // end isValidDate function[/color]

                        Bloated; and I was going to say that it did not discriminate between
                        months of 28,29,30,31 days. But that pales into insignificance when one
                        sees that you only allow 12 days in each month.

                        I know what cint does in VBScript, but not of its use in javascript.

                        You appear to be checking an 8-digit field; but your strings call for
                        FFF dates, mm/dd/yyyy. Did you intend to allow a 101-year range?

                        Proper date validation need not be lengthy; see sig.

                        [color=blue]
                        >function isValidName (testName) {
                        >var myRegExp = /[A-Z][a-z]{1,29}/;
                        >//alert (myRegExp.test( testName));
                        >return myRegExp.test(t estName);
                        >} // end isValidName function[/color]

                        That accepts "Ug", though it rejects "U Thant"

                        It accepts "Llanfairpwllgw yngyllgogerychw yrndrobwllllant ysiliogogogoch"
                        and also "llanfairpwllgw yngyllgogerychw yrndrobw1111ant ysiIiogogogoch" .
                        You may not have expected that. It also accepts "00000Ol111111" .
                        It accepts ("O'Keefe") which IIRC is the name of a NASA boss; but I
                        suspect that's accidental.

                        [color=blue]
                        >function isValidPhone (testPhone) {
                        >var myRegExp = /[1-9][0-9]{2}-[0-9]{4}/;
                        >return myRegExp.test(t estPhone);[/color]

                        Appears to require the form ddd-dddd to be somewhere in the input.
                        Strings call for xxx-xxx-xxxx.
                        [color=blue]
                        >} // end isValidPhone function
                        >
                        >function isValidEmail (testEmail) {
                        >var myRegExp =
                        >/[a-z0-9.]{1,40}@[a-z0-9.]{4,65}.(com|net |org|info|biz|([a-z]{2,3}.[a-z]{2}))/;
                        >return myRegExp.test(t estEmail)
                        >} // end isValidEmail function[/color]

                        Rejects many valid left parts. Rejects "xxx@yyy.co.uk" , which is valid.
                        Accepts "##x@yy7y.co.uk " which may be valid but is evidently not
                        intended. Accepts "Joe Stalin@yy7y.Leo nid Brezhnev") .
                        [color=blue]
                        >function getStyleObject (objectId) {
                        >//alert ("begin getSyleObject") ;[/color]
                        ^ <G>[color=blue]
                        >//if (document.getEl ementById && document.getEle mentById(object Id))
                        >{
                        >//alert ("break 1 in getStyleObject" );
                        >return document.getEle mentById(object Id).style;
                        >//}
                        >//else if (document.all && document.all(ob jectId)) {
                        >//alert ("break 2 in getStyleObject" );
                        >//return document.all(ob jectId).style;
                        >//}
                        >//else if (document.layer s && document.layers[objectId]) {
                        >//alert ("break 3 in getStyleObject" );
                        >//return document.layers[objectId];
                        >//}
                        >//else {
                        >//alert ("break 4 in getStyleObject" );
                        >//return false;
                        >//}
                        >//alert ("end getSyleObject") ;
                        >}[/color]

                        Does that mean that your Air Force still has Netscape 4???
                        [color=blue]
                        >function suspendSpouse(o bjectId) {[/color]

                        Seems a tactless function identifier <g>.

                        ISTM that your Air Force should employ a programmer to do your task.

                        --
                        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                        <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                        Comment

                        Working...