Solved

Validation of a dynamically generated Javascript table within a web form.

Posted on 2006-07-17
10
341 Views
Last Modified: 2012-05-05
Hello Experts,
I need assistance in figuring out the validation code on a page that uses Javascript to dynamically build a table that will eventually be sent on to an Action page for processing. The form's purpose is to allow users to submit registration information via a webform to request a new account.  The table's header row is built within an HTML form and blank 'data input rows' are added/removed when the user clicks on Add or Remove buttons. The JavaScripted "rows" contain a total of 9 cells all of which need to be validated on the client before allowing the form to submit. All but one of the row's 8 cells are free text input along with one cell that's a drop-down select box. The code below all works and successfully posts the information over to an Action page that in-turn submits an email (using the cfmail tag) formatted in HTML.

The basic client-side validation checks that are needed:
1) FirstName -
- A required text field that must contain at least two alpha characters with a maximum of 20. Generate an alert message, and block
submission, so the form's user can go back and make the required corrections.  
- Basic security-related checks to see if the text string contains "malicious" (think SQL injection) commonly known string sequences.    

2) LastName -
-  Is a "required" text field and must contain at least two alpha characters with a maximum of 30.
- Basic security-related checks to see if the string contains "malicious" (think SQL injection) common string sequences.

3) Position or Role -
- Is a drop-down select box, with a default value = '0' and requires selection of a list member.  

4) The remaining 6 fields are all free text input and are not required. If entries are present in these fields, they must also be examined for "malicious" string sequences and that they do not exceede the max-length.  

Here are the relevant code sections:
===========================================
JavaScript to build or remove input rows:
============================================
//Begin Add Input Row function for Practice Worksheet Members List
function addRowToTable()
{
  var tbl = document.getElementById('practice_members');
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
 
// Row Number Iteration
    var cellLeft = row.insertCell(0);
    var textNode = document.createTextNode(iteration);
    cellLeft.appendChild(textNode);
    cellLeft.className = "Enrollment_InputBox";

//Set iteration = to lastRow count
   document.getElementById('iteration').value = lastRow;

// Username
    var cellRight = row.insertCell(1);
    var el = document.createElement(
    "<input class='Enrollment_InputBox' type='text' name='Username"+ iteration +"' id='Username"+ iteration +"' size='8' maxlength='15'>");
    cellRight.appendChild(el);

// First Name
    var cellRight = row.insertCell(2);
    var el = document.createElement(
    "<input class='Enrollment_InputBox' type='text' name='FirstName"+ iteration +"' id='FirstName"+ iteration +"' size='10' maxlength='20'>");
    cellRight.appendChild(el);
 
// Middle Initial
    var cellRight = row.insertCell(3);
    var el = document.createElement(
    "<input class='Enrollment_InputBox' type='text' name='MiddleInitial"+ iteration +"' id='MiddleInitial"+ iteration +"' size='1'

maxlength='1'>");
     cellRight.appendChild(el);

// Last Name
    var cellRight = row.insertCell(4);
    var el = document.createElement(
    "<input class='Enrollment_InputBox' type='text' name='LastName"+ iteration +"' id='LastName"+ iteration +"' size='10' maxlength='30'>");
    cellRight.appendChild(el);
 
// Name Suffix
      var cellRight = row.insertCell(5);
      var el = document.createElement(
      "<input class='Enrollment_InputBox' type='text' name='NameSuffix"+ iteration +"' id='NameSuffix"+ iteration +"' size='2'

maxlength='2'>");
      cellRight.appendChild(el);  

// Position or Role
    var cellRightSel = row.insertCell(6);
    var sel = document.createElement('select');
        sel.name = 'PositionRole'+ iteration;
      sel.className = 'Enrollment_SelectBox';
      sel.options[0] = new Option('Select...', 0);
      sel.options[1] = new Option('Referring Physician', 'Referring Physician');
      sel.options[2] = new Option('Nurse', 'Nurse');
      sel.options[3] = new Option('Office Staff', 'Office Staff');
        cellRightSel.appendChild(sel);
// UPIN
    var cellRight = row.insertCell(7);
    var el = document.createElement(
     "<input class='Enrollment_InputBox' type='text' name='UPIN"+ iteration +"' id='UPIN"+ iteration +"' size='8' maxlength='10'>");
      cellRight.appendChild(el);
 
// Email
    var cellRight = row.insertCell(8);
    var el = document.createElement(
    "<input class='Enrollment_InputBox' type='text' name='Email"+ iteration +"' id='Email"+ iteration +"' size='25' maxlength='65'>");
    cellRight.appendChild(el);      

// Phone
    var cellRight = row.insertCell(9);
    var el = document.createElement(
    "<input class='Enrollment_InputBox' type='text' name='Phone"+ iteration +"' id='Phone"+ iteration +"' size='15' maxlength='20'>");
    cellRight.appendChild(el);
}
//End Add Input Row function for Practice Worksheet Members List

//Begin Delete Last Input Row function for Practice Worksheet Members List
    function removeRowFromTable()
    {
    var tbl = document.getElementById('practice_members');
    var lastRow = tbl.rows.length;
    if (lastRow > 1) {
    tbl.deleteRow(lastRow - 1);  
    lastRow = tbl.rows.length;
    document.getElementById('iteration').value = lastRow -1;
   }
}
//End Delete Last Input Row function for Practice Worksheet Members List
      
// Begin Practice worksheet FORM Submit Function
    function FormActionSubmitPracticeWorksheet()  {
      document.PracticeWorksheet.action = "PracticeWorksheetAction.cfm";
      if (ValidateFieldsWs()== true){
            alert("Your Referring Medical Practice Worksheet has been Submitted.");
                  document.PracticeWorksheet.submit();      
            }
            return false;
      }
// End FORM SUBMIT FUNCTIONS
            
=================================================
Related HTML containing table's header row and buttons:
==================================================
<cfform  name="PracticeWorksheet" id="PracticeWorksheet" >
...
...
<table class="Enrollment_MembrTbl" id="practice_members" border="1"  cellpadding="0" cellspacing="0">
              <div align="center" class="Enrollment_RowSpacer">
          <span  class="Enrollment_TblHead" style="color: #003399; font-weight: bold">Practice Member Information</span>
      </div>
                  <tr>
                       <th valign="bottom" class="Enrollment_ColHead">Row</th>
        <th valign="bottom" class="Enrollment_ColHead">Username<span class="Enrollment_Notation">1</span></th>
                       <th valign="bottom" class="Enrollment_ColHead"><span class="Enrollment_Asterik">*</span>First Name</th>
                       <th valign="bottom" class="Enrollment_ColHead">M.I.</th>
                       <th valign="bottom" class="Enrollment_ColHead"><span class="Enrollment_Asterik">*</span>Last Name</th>
                       <th valign="bottom" class="Enrollment_ColHead">Suffix</th>
                       <th valign="bottom" class="Enrollment_ColHead"><span class="Enrollment_Asterik">*</span>Position or Role</th>
                       <th valign="bottom" class="Enrollment_ColHead">UPIN</th>
                       <th valign="bottom" class="Enrollment_ColHead">Email</th>
                       <th valign="bottom" class="Enrollment_ColHead">Phone</th>
                  </tr>
      <input type="hidden" name="iteration" id="iteration" value="0">
</table>
<p align="center">
<input name="button" type="button" style="cursor:pointer" class="Enrollment_InputBox" value="Add a Member"

onClick="addRowToTable();"/>
<input name="button" type="button" style="cursor:pointer" class="Enrollment_InputBox" value="Remove Last Member"

onClick="removeRowFromTable();"/>
</p>
<p align="center">
<input name="button"  type="button" style="cursor:pointer" class="Enrollment_InputBox" value="Submit Worksheet"

onClick="FormActionSubmitPracticeWorksheet()">
</p>
</cfform>


Thanks and your assistance with this is greately appreciated!
0
Comment
Question by:edwill
  • 5
  • 5
10 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17128118
How does
   ValidateFieldsWs()
look?
0
 

Author Comment

by:edwill
ID: 17129882
Hello mplungjan,
ValidateFieldsWs() looks like:
// Begin Practice Worksheet field validation
function ValidateFieldsWs()      {      
      //validate required fields and field input.
              var blnResultWs = true;
              var sMessageWs = "\n";
              var chklenWs = "";
            var checkEmailWs = "";
            var i = "";
            
            //Begin Validate Country is present
            if (document.PracticeWorksheet.first_practice_country.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_country.focus();
               document.PracticeWorksheet.first_practice_country.select();
               sMessageWs = "* Country is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Country is present
            
                                //Begin Validate Zip Postal Code is present
            if (document.PracticeWorksheet.first_practice_zip.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_zip.focus();
               document.PracticeWorksheet.first_practice_zip.select();
               sMessageWs = "* Zip or Postal Code is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Zip Postal Code is present
             
                                //Begin Validate State or Provience is present
            if (document.PracticeWorksheet.first_practice_state.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_state.focus();
               document.PracticeWorksheet.first_practice_state.select();
               sMessageWs = "* State or Province is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate State is present

            //Begin Validate City is present
            if (document.PracticeWorksheet.first_practice_city.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_city.focus();
               document.PracticeWorksheet.first_practice_city.select();
               sMessageWs = "* City is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate City is present

            //Begin Validate Address is present
            if (document.PracticeWorksheet.first_practice_address.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_address.focus();
               document.PracticeWorksheet.first_practice_address.select();
               sMessageWs = "* Address is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Address is present

            //Begin Validate Fax is present
            if (document.PracticeWorksheet.first_practice_fax.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_fax.focus();
               document.PracticeWorksheet.first_practice_fax.select();
               sMessageWs = "* Fax is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Fax is present

            //Begin Validate Primary Practice phone is present
            if (document.PracticeWorksheet.first_practice_primary_phone.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_primary_phone.focus();
               document.PracticeWorksheet.first_practice_primary_phone.select();
               sMessageWs = "* Phone is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Primary Practice phone is present

            //Begin Validate Primary Practice Contact is present
            if (document.PracticeWorksheet.PracticeCONTACT.value.length + 1 < 2)
            {
               document.PracticeWorksheet.PracticeCONTACT.focus();
               document.PracticeWorksheet.PracticeCONTACT.select();
               sMessageWs = "* Practice Contact is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Contact is present

            //Begin Validate Primary Practice Name is present
            if (document.PracticeWorksheet.PracticeNAME.value.length + 1 < 2)
            {
               document.PracticeWorksheet.PracticeNAME.focus();
               document.PracticeWorksheet.PracticeNAME.select();
               sMessageWs = "* Practice Name is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Primary Practice Name is present
            
            //Begin Validate Senders email is present and in a valid format eg:email@somewhere.com
            var chklenWs = document.PracticeWorksheet.MailFrom.value.length + 1;
            var checkEmailWs = document.PracticeWorksheet.MailFrom.value
                  if (chklenWs > 1){
                        if ((checkEmailWs.indexOf('@') < 0) || ((checkEmailWs.charAt(checkEmailWs.length - 5) != '.') && (checkEmailWs.charAt(checkEmailWs.length - 4) != '.') && (checkEmailWs.charAt(checkEmailWs.length - 3) != '.'))){
                              document.PracticeWorksheet.MailFrom.focus();
                                document.PracticeWorksheet.MailFrom.select();
                              sMessageWs = "* Invalid Email address format.\n" + sMessageWs;
                                 blnResultWs = false;
                        }}
                  else {
                              document.PracticeWorksheet.MailFrom.focus();
                                document.PracticeWorksheet.MailFrom.select();
                              sMessageWs = "* A Valid Email address is required.\n" + sMessageWs;
                                 blnResultWs = false;
                  }
            //End Validate Senders email is present and valid format
            
            //Begin Validate To: Location Selection was made
            if (document.PracticeWorksheet.LocationWs.value == "0")
            {
                  document.PracticeWorksheet.LocationWs.focus();
                  sMessageWs = "* A Clinic destination is required.\n" + sMessageWs;
                     blnResultWs = false;
                                }
            //End Validate To: Location Selection was made
       
      //Begin Error trap and Message box
      if (blnResultWs == false){
                  sMessageWs = "The following errors have occured on the Practice Worksheet.\n \n" + sMessageWs;
                   alert(sMessageWs);
            }
             return blnResultWs;      
      }
      
The cfinput form, name=PracticeWorksheet, contains two main tables. ValidateFieldsWs covers all the input fields contained in the 'upper' table portion of the form and currently works fine. In that the second table in cfform=Practiceworksheet , table id=practice_members, is a dynamically built table, I'm not sure if (or how) ValidateFieldsWs() would be coded to include validation for table id=practice_worksheet...?    
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17130135
for (i=0, n= parseInt(document.getElementById('iteration').value);i<n;i++)  {
      if (document.PracticeWorksheet.elements["Username"+ i].value.length + 1 < 2)
          {
             document.PracticeWorksheet.elements["Username"+ i].focus();
             document.PracticeWorksheet.elements["Username"+ i].select();
             sMessageWs = "* Username is required.\n" + sMessageWs;
             blnResultWs = false;
          }
      if (document.PracticeWorksheet.elements["FirstName"+ i].value.length + 1 < 2)
          {
             document.PracticeWorksheet.elements["FirstName"+ i].focus();
             document.PracticeWorksheet.elements["FirstName"+ i].select();
             sMessageWs = "* First Name is required.\n" + sMessageWs;
             blnResultWs = false;
          }
.
.
.
}

Michel
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:edwill
ID: 17131444
Inserting the new code blocks:

function ValidateFieldsWs()      {      
//validate required fields and field input.
  var blnResultWs = true;
  var sMessageWs = "\n";
  var chklenWs = "";
  var checkEmailWs = "";
  var i = "";
            
      for (i=0, n= parseInt(document.getElementById('iteration').value);i<n;i++) {
      if (document.PracticeWorksheet.elements["Username"+ i].value.length + 1 < 2)
      {
                  document.PracticeWorksheet.elements["Username"+ i].focus();
                  document.PracticeWorksheet.elements["Username"+ i].select();
                  sMessageWs = "* Username is required.\n" + sMessageWs;
                  blnResultWs = false;
               }

      if (document.PracticeWorksheet.elements["FirstName"+ i].value.length + 1 < 2)
      {
                   document.PracticeWorksheet.elements["FirstName"+ i].focus();
                   document.PracticeWorksheet.elements["FirstName"+ i].select();
                   sMessageWs = "* First Name is required.\n" + sMessageWs;
                   blnResultWs = false;
      }
            }

Throws a JScript error: 'document.PracticeWorksheet.elements[...].value' is null or not an object

I tried to change .elements to .Element and still no luck.
      
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 17135958
it is elements.

Please show me a view-source of a real page - my email is in my profile
0
 

Author Comment

by:edwill
ID: 17137757
Copy of the code that uses the direction provided by mplungjan. You assistance in helping figure this out is greatly appreciated! etw.
 //---------------- Begin Practice Worksheet JavaScripts ----------------------->
// BEGIN TOGGLE SHOW/NOSHOW PRACTICE WORKSHEET FORM
      function togglePracticeWorksheetDec(evt) {
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var block = document.getElementById("PracticeWorksheet");
    if (target.id == "PracticeWorksheet1") {
        block.style.display = "block";
    } else {
        block.style.display = "none";  
    }
}
// END TOGGLE SHOW/NOSHOW PRACTICE WORKSHEET FORM
//Begin Add Input Row function for Practice Worksheet Members List
function addRowToTable()
{
  var tbl = document.getElementById('practice_members');
  var lastRow = tbl.rows.length;
  // iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  // Row Number Iteration
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(iteration);
  cellLeft.appendChild(textNode);
  cellLeft.className = "Enrollment_InputBox";
 //Set iteration = to lastRow count
 document.getElementById('iteration').value = lastRow;
  // Username
  var cellRight = row.insertCell(1);
  var el = document.createElement(
                    "<input class='Enrollment_InputBox' type='text' name='Username"+ iteration +"' id='Username"+ iteration +"' size='8' maxlength='15'>");
  cellRight.appendChild(el);
  // First Name
  var cellRight = row.insertCell(2);
  var el = document.createElement(
                    "<input class='Enrollment_InputBox' type='text' name='FirstName"+ iteration +"' id='FirstName"+ iteration +"' size='10' maxlength='20'>");
  cellRight.appendChild(el);
  // Middle Initial
  var cellRight = row.insertCell(3);
  var el = document.createElement(
                    "<input class='Enrollment_InputBox' type='text' name='MiddleInitial"+ iteration +"' id='MiddleInitial"+ iteration +"' size='1' maxlength='1'>");
  cellRight.appendChild(el);
  // Last Name
  var cellRight = row.insertCell(4);
  var el = document.createElement(
                    "<input class='Enrollment_InputBox' type='text' name='LastName"+ iteration +"' id='LastName"+ iteration +"' size='10' maxlength='15'>");
  cellRight.appendChild(el);  
  // Name Suffix
  var cellRight = row.insertCell(5);
  var el = document.createElement(
                    "<input class='Enrollment_InputBox' type='text' name='NameSuffix"+ iteration +"' id='NameSuffix"+ iteration +"' size='2' maxlength='2'>");
  cellRight.appendChild(el);  
  // Position or Role
  var cellRightSel = row.insertCell(6);
  var sel = document.createElement('select');
        sel.name = 'PositionRole'+ iteration;
        sel.id = 'PositionRole'+ iteration;
      sel.className = 'Enrollment_SelectBox';
      sel.options[0] = new Option('Select...', '0');
      sel.options[1] = new Option('Referring Physician', 'Referring Physician');
      sel.options[2] = new Option('Nurse', 'Nurse');
      sel.options[3] = new Option('Office Staff', 'Office Staff');
        cellRightSel.appendChild(sel);
  // UPIN
  var cellRight = row.insertCell(7);
  var el = document.createElement(
                    "<input class='Enrollment_InputBox' type='text' name='UPIN"+ iteration +"' id='UPIN"+ iteration +"' size='8' maxlength='10'>");
  cellRight.appendChild(el);
  // Email
  var cellRight = row.insertCell(8);
  var el = document.createElement(
                    "<input class='Enrollment_InputBox' type='text' name='Email"+ iteration +"' id='Email"+ iteration +"' size='25' maxlength='65'>");
    cellRight.appendChild(el);      
  // Phone
  var cellRight = row.insertCell(9);
  var el = document.createElement(
                    "<input class='Enrollment_InputBox' type='text' name='Phone"+ iteration +"' id='Phone"+ iteration +"' size='15' maxlength='20'>");
    cellRight.appendChild(el);
}
//End Add Input Row function for Practice Worksheet Members List
//Begin Delete Last Input Row function for Practice Worksheet Members List
function removeRowFromTable()
{
  var tbl = document.getElementById('practice_members');
  var lastRow = tbl.rows.length;
  if (lastRow > 1) {
  tbl.deleteRow(lastRow - 1);  
   lastRow = tbl.rows.length;
   document.getElementById('iteration').value = lastRow -1;
   
   }
}
//End Delete Last Input Row function for Practice Worksheet Members List

// Begin Practice Worksheet field validation
function isDefined(variable){
      return (!(!(document.getElementById(variable))))
}

 
function ValidateFieldsWs()      {      
      //validate required fields and field input.
              var blnResultWs = true;
              var sMessageWs = "\n";
              var chklenWs = "";
            var checkEmailWs = "";
            var i = "";


        var it = document.getElementById('iteration').value;
        // check to see if at least one user has been added
        
            var itc = document.getElementById('iteration').value + 1;
            for (var its=1;its<itc;its++){
            // loop through rows
                  // Start check PositionRole
                  if (isDefined('PositionRole'+its)){
                        if (document.getElementById('PositionRole'+its).value == "0"){
                           document.getElementById('PositionRole'+its).focus();
                           sMessageWs = "* In Row "+its+" a selection for Position Role is required.\n" + sMessageWs;
                           blnResultWs = false;
                        }
                  }
                  // End check PositionRole

                  // Start check LastName
                  if (isDefined('LastName'+its)){
                        if (document.getElementById('LastName'+its).value.length < 2){
                           document.getElementById('LastName'+its).focus();
                           document.getElementById('LastName'+its).select();
                           sMessageWs = "* In Row "+its+" Last Name must be two or more characters.\n" + sMessageWs;
                           blnResultWs = false;
                        }
                  }
                  // End check LastName

                  // Start check firstname
                  if (isDefined('FirstName'+its)){
                        if (document.getElementById('FirstName'+its).value.length < 1){
                           document.getElementById('FirstName'+its).focus();
                           document.getElementById('FirstName'+its).select();
                           sMessageWs = "* In Row "+its+" First Name must be one or more characters.\n" + sMessageWs;
                           blnResultWs = false;
                        }
                  }
                  // End check firstname
              }
            if (it < 1) {
               addRowToTable();
                  document.getElementById('Username1').focus();
               document.getElementById('Username1').select();
               sMessageWs = "* Practice member information is required.\n" + sMessageWs;
                blnResultWs = false;
        }
        
            //Begin Validate Country is present
            if (document.PracticeWorksheet.first_practice_country.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_country.focus();
               document.PracticeWorksheet.first_practice_country.select();
               sMessageWs = "* Country is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Country is present
            //Begin Validate Zip Postal Code is present
            if (document.PracticeWorksheet.first_practice_zip.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_zip.focus();
               document.PracticeWorksheet.first_practice_zip.select();
               sMessageWs = "* Zip or Postal Code is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Zip Postal Code is present
            //Begin Validate Zip Postal Code is present
            if (document.PracticeWorksheet.first_practice_state.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_state.focus();
               document.PracticeWorksheet.first_practice_state.select();
               sMessageWs = "* State or Province is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Zip Postal Code is present
            //Begin Validate City Postal Code is present
            if (document.PracticeWorksheet.first_practice_city.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_city.focus();
               document.PracticeWorksheet.first_practice_city.select();
               sMessageWs = "* City is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate City is present
            //Begin Validate Address is present
            if (document.PracticeWorksheet.first_practice_address.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_address.focus();
               document.PracticeWorksheet.first_practice_address.select();
               sMessageWs = "* Address is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Address is present
            //Begin Validate Fax is present
            if (document.PracticeWorksheet.first_practice_fax.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_fax.focus();
               document.PracticeWorksheet.first_practice_fax.select();
               sMessageWs = "* Fax is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Fax is present
            //Begin Validate Primary Practice phone is present
            if (document.PracticeWorksheet.first_practice_primary_phone.value.length + 1 < 2)
            {
               document.PracticeWorksheet.first_practice_primary_phone.focus();
               document.PracticeWorksheet.first_practice_primary_phone.select();
               sMessageWs = "* Phone is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Phone is present
            //Begin Validate Primary Practice Contact is present
            if (document.PracticeWorksheet.PracticeCONTACT.value.length + 1 < 2)
            {
               document.PracticeWorksheet.PracticeCONTACT.focus();
               document.PracticeWorksheet.PracticeCONTACT.select();
               sMessageWs = "* Practice Contact is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Contact is present
            //Begin Validate Primary Practice Name is present
            if (document.PracticeWorksheet.PracticeNAME.value.length + 1 < 2)
            {
               document.PracticeWorksheet.PracticeNAME.focus();
               document.PracticeWorksheet.PracticeNAME.select();
               sMessageWs = "* Practice Name is required.\n" + sMessageWs;
               blnResultWs = false;
            }
            //End Validate Primary Practice Name is present
            
            //Begin Validate Senders email is present and in a valid format eg:email@somewhere.com
            var chklenWs = document.PracticeWorksheet.MailFrom.value.length + 1;
            var checkEmailWs = document.PracticeWorksheet.MailFrom.value
                  if (chklenWs > 1){
                        if ((checkEmailWs.indexOf('@') < 0) || ((checkEmailWs.charAt(checkEmailWs.length - 5) != '.') && (checkEmailWs.charAt(checkEmailWs.length - 4) != '.') && (checkEmailWs.charAt(checkEmailWs.length - 3) != '.'))){
                              document.PracticeWorksheet.MailFrom.focus();
                                document.PracticeWorksheet.MailFrom.select();
                              sMessageWs = "* Invalid Email address format.\n" + sMessageWs;
                                 blnResultWs = false;
                        }}
                  else {
                              document.PracticeWorksheet.MailFrom.focus();
                                document.PracticeWorksheet.MailFrom.select();
                              sMessageWs = "* A Valid Email address is required.\n" + sMessageWs;
                                 blnResultWs = false;
                  }
            //End Validate Senders email is present and valid format
            
            //Begin Validate To: Location Selection was made
            if (document.PracticeWorksheet.LocationWs.value == "0")
            {
                  document.PracticeWorksheet.LocationWs.focus();
                  sMessageWs = "* A Clinic destination is required.\n" + sMessageWs;
                     blnResultWs = false;
          }
            //End Validate To: Location Selection was made
       
      //Begin Error trap and Message box
      if (blnResultWs == false){
                  sMessageWs = "The following errors have occured on the Practice Worksheet.\n \n" + sMessageWs;
                   alert(sMessageWs);
            }
             return blnResultWs;      
      }
      
      
//******************************************************************************      
// End Practice Worksheet field validation
//******************************************************************************      
 //******************************************************************************      
// Begin Practice worksheet FORM Submit Function
//******************************************************************************      
      function FormActionSubmitPracticeWorksheet()  {
            document.PracticeWorksheet.action = "PracticeWorksheetAction.cfm";
            if (ValidateFieldsWs()== true){
                  alert("Your Referring Medical Practice Worksheet has been Submitted.");
                  document.PracticeWorksheet.submit();      
            }
//            document.PracticeWorksheet.action = "FormTester.cfm";
//                  document.PracticeWorksheet.submit();      
            return false;
      }
//******************************************************************************      
// End FORM SUBMIT FUNCTIONS
//******************************************************************************
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17137859
I assume you have a problem with this:

var itc = document.getElementById('iteration').value + 1;

should be
var itc = parseInt(document.getElementById('iteration').value) + 1;
0
 

Author Comment

by:edwill
ID: 17137884
No problem was detected or reported but let me go back and make the change and do some more testing. Thanks!
0
 

Author Comment

by:edwill
ID: 17137971
Seems no problem is detected with or without using parseInt(... Therefore, I'll leave it set this way. Can't hurt, right?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17138384
Adding one line and using

var itc = document.getElementById('iteration').value + 1;
alert(itc)

will alert 11

using
var itc = parseInt(document.getElementById('iteration').value) + 1;
it alerts 2 which is correct in this case
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question