Solved

checkdate function giving undefined error

Posted on 2003-11-03
30
466 Views
Last Modified: 2007-12-19
Hi!

I am calling the following javascript via the following two statements on an xsl page:

<td align="center">
            <input maxLength="8" name="startdt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
           </td>
          <td align="center">
            <input maxLength="8" name="enddt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
           </td>

I am getting the following error when I am leaving the start date field whether or not a value is entered:

startdt is undefined

Any ideas?

Chuck

 var dosubmit = true;

    function checkDates()
    {

          var sStartDate;
          var sEndDate;

           if (!checkDate(startdt)) return false;
           if (!checkDate(enddt)) return false;

          sStartDate = startdt.value;
          sEndDate = enddt.value;

           dtStartDate = ConvertStringToDate(startdt.value);
           dtEndDate = ConvertStringToDate(sEndDate);

           if (dtStartDate > dtEndDate)
           {
                alert('The end date (' + sEndDate + ') is earlier than the start date (' + sStartDate + ')');
                return false;
           }

           return true;

     }

     function ConvertStringToDate(sDate)
     {

          var sDateArray;
          var iMonth;
          var iDay;
          var iYear;

          if (sDate.indexOf('/') != -1)
           {
                sDateArray = sDate.split('/');
               iMonth = parseInt(sDateArray[0], 10);
               iDay = parseInt(sDateArray[1], 10);
               iYear = parseInt(sDateArray[2], 10);
           }

          return new Date(iYear, iMonth, iDay);

     }


   function checkDate(oDateElem, sDate)
   {


             var sDate = oDateElem.value;

             if (sDate.length < 1)
           {
                return true;
           }

           if (sDate.indexOf('/') != -1)
           {
                sDateArray = sDate.split('/');
                if (sDateArray.length != 3)
               {
                    alert('Invalid date (' + sDate + ').');
                    oDateElem.focus();
                    return false;
               }
                sMonth = sDateArray[0];
                sDay = sDateArray[1];
                sYear = sDateArray[2];
           }

           if (sYear.length == 1)
           {
                sYear = '200' + sYear;
           }
           if (sYear.length == 2)
           {
                sYear = '20' + sYear;
           }

           iDay = parseInt(sDay, 10);

           if (isNaN(iDay))
           {
               alert('Invalid date (' + sDate + ').');
               oDateElem.focus();
               return false;
           }

           iMonth = parseInt(sMonth, 10);
           if (isNaN(iMonth))
           {
               alert('Invalid date (' + sDate + ').');
               oDateElem.focus();
               return false;
           }

           iYear = parseInt(sYear, 10);
           if (isNaN(iYear))
           {
               alert('Invalid date (' + sDate + ').');
               oDateElem.focus();
               return false;
           }

           if (iYear < 1900 || iYear > 2078)
           {
               alert('Invalid date - year must be between 1900 and 2078 (' + sDate + ').');
               oDateElem.focus();
               return false;
           }


           if (iMonth > 12 || iMonth < 1)
           {
               alert('Invalid date - month must be between 1 and 12 (' + sDate + ').');
               oDateElem.focus();
               return false;
           }

           if ((iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12) && (iDay > 31 || iDay < 1))
           {
               alert('Invalid date - day must be between 1 and 31 (' + sDate + ').');
               oDateElem.focus();
               return false;
           }

           if ((iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) && (iDay > 30 || iDay < 1))
           {
               alert('Invalid date - day must be between 1 and 30 (' + sDate + ').');
               oDateElem.focus();
               return false;
           }

           if (iMonth == 2)
           {
                if (LeapYear(iYear) == true)
                {
                     if (iDay < 1 || iDay > 29)
                     {
                         alert('Invalid date - day must be between 1 and 29 (' + sDate + ').');
                         oDateElem.focus();
                         return false;
                     }
                }
                else
                {
                     if (iDay < 1 || iDay > 28)
                     {
                         alert('Invalid date - day must be between 1 and 28 (' + sDate + ').');
                         oDateElem.focus();
                         return false;
                     }
                }
           }

          oDateElem.value = iMonth + "/" + iDay + "/" + iYear;

           return true;
     }


     function LeapYear(iYear)
     {
          if (iYear % 100 == 0)
          {
               if (iYear % 400 == 0)
               {
                    return true;
               }
          }
          else
          {
               if ((iYear % 4) == 0)
               {
                    return true;
               }
          }
          return false;
     }
0
Comment
Question by:TrueBlue
  • 9
  • 8
  • 8
  • +2
30 Comments
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
um...
1.u can use a form
<form name=fm1>
<td align="center">
           <input maxLength="8" name="startdt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
          </td>
         <td align="center">
           <input maxLength="8" name="enddt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
          </td>
</form>

then,  in the function
         sStartDate = document.fm1.startdt.value;
         sEndDate = document.fm1.enddt.value;
----------------------------------------------------------------------------------------
or

           <input maxLength="8" id="startdt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
          </td>
         <td align="center">
           <input maxLength="8" id="enddt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
          </td>

then,  in the function
         sStartDate = document.all.startdt.value;
         sEndDate = document.all.enddt.value;

hope this helps



0
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
because "startdt"  is the name  of the input field
but a JS variable
0
 

Author Comment

by:TrueBlue
Comment Utility
Hi ho_alan!

I used your second method, but unfortunately I get the exact same error.

If I understood correctly, you wanted me to substitue this:
 sStartDate = startdt.value;
 sEndDate = enddt.value;

with this:

 sStartDate = document.all.startdt.value;
 sEndDate = document.all.enddt.value;
 
Any other ideas?

Chuck
0
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
um...u should  change

all  "startdt" and "enddt"
to be "document.all.startdt" and "document.all.enddt"

eg.
   if (!checkDate(document.all.startdt)) return false;
          if (!checkDate(document.all.enddt)) return false;

         sStartDate = document.all.startdt.value;
         sEndDate = document.all.enddt.value;

hope this  helps
0
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
i have tried,should work  without error

<html>
<body>
<script>
var dosubmit = true;

   function checkDates()
   {

         var sStartDate= document.all.startdt;
         var sEndDate= document.all.enddt;

          if (!checkDate(sStartDate))  return false;
          if (!checkDate(sEndDate)) ; return false;


          dtStartDate = ConvertStringToDate(document.all.startdt.value);
          dtEndDate = ConvertStringToDate(sEndDate);

          if (dtStartDate > dtEndDate)
          {
               alert('The end date (' + sEndDate + ') is earlier than the start date (' + sStartDate + ')');
               return false;
          }

          return true;

    }

    function ConvertStringToDate(sDate)
    {

         var sDateArray;
         var iMonth;
         var iDay;
         var iYear;

         if (sDate.indexOf('/') != -1)
          {
               sDateArray = sDate.split('/');
              iMonth = parseInt(sDateArray[0], 10);
              iDay = parseInt(sDateArray[1], 10);
              iYear = parseInt(sDateArray[2], 10);
          }

         return new Date(iYear, iMonth, iDay);

    }


  function checkDate(oDateElem)
  {


            var sDate = oDateElem.value;

            if (sDate.length < 1)
          {
               return true;
          }

          if (sDate.indexOf('/') != -1)
          {
               sDateArray = sDate.split('/');
               if (sDateArray.length != 3)
              {
                   alert('Invalid date (' + sDate + ').');
                   oDateElem.focus();
                   return false;
              }
               sMonth = sDateArray[0];
               sDay = sDateArray[1];
               sYear = sDateArray[2];
          }

          if (sYear.length == 1)
          {
               sYear = '200' + sYear;
          }
          if (sYear.length == 2)
          {
               sYear = '20' + sYear;
          }

          iDay = parseInt(sDay, 10);

          if (isNaN(iDay))
          {
              alert('Invalid date (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          iMonth = parseInt(sMonth, 10);
          if (isNaN(iMonth))
          {
              alert('Invalid date (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          iYear = parseInt(sYear, 10);
          if (isNaN(iYear))
          {
              alert('Invalid date (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          if (iYear < 1900 || iYear > 2078)
          {
              alert('Invalid date - year must be between 1900 and 2078 (' + sDate + ').');
              oDateElem.focus();
              return false;
          }


          if (iMonth > 12 || iMonth < 1)
          {
              alert('Invalid date - month must be between 1 and 12 (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          if ((iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12) && (iDay > 31 || iDay < 1))
          {
              alert('Invalid date - day must be between 1 and 31 (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          if ((iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) && (iDay > 30 || iDay < 1))
          {
              alert('Invalid date - day must be between 1 and 30 (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          if (iMonth == 2)
          {
               if (LeapYear(iYear) == true)
               {
                    if (iDay < 1 || iDay > 29)
                    {
                        alert('Invalid date - day must be between 1 and 29 (' + sDate + ').');
                        oDateElem.focus();
                        return false;
                    }
               }
               else
               {
                    if (iDay < 1 || iDay > 28)
                    {
                        alert('Invalid date - day must be between 1 and 28 (' + sDate + ').');
                        oDateElem.focus();
                        return false;
                    }
               }
          }

         oDateElem.value = iMonth + "/" + iDay + "/" + iYear;

          return true;
    }


    function LeapYear(iYear)
    {
         if (iYear % 100 == 0)
         {
              if (iYear % 400 == 0)
              {
                   return true;
              }
         }
         else
         {
              if ((iYear % 4) == 0)
              {
                   return true;
              }
         }
         return false;
    }

</script>
<td align="center">
           <input maxLength="8" id="startdt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
          </td>
         <td align="center">
           <input maxLength="8" id="enddt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
          </td
</body>
</html>
0
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
no ";",i mistyped it
         if (!checkDate(sEndDate))  return false;

please tell if u still have problems  :-)
0
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
please wait
i am  making some changes for u

is that if user enters "1"
then it will be converted to "1/1/2000"?
0
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
ok, i got it
please wait for my final version
0
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
<html>
<body>
<script language=javascript>
var dosubmit = true;

   function checkDates()
   {

         var sStartDate= document.all.startdt;
         var sEndDate= document.all.enddt;

          if (!checkDate(sStartDate))  return false;
          if (!checkDate(sEndDate))  return false;


          dtStartDate = ConvertStringToDate(sStartDate.value);
          dtEndDate = ConvertStringToDate(sEndDate.value);

          if (dtStartDate > dtEndDate)
          {
               alert('The end date (' + sEndDate.value + ') is earlier than the start date (' + sStartDate.value + ')');
               return false;
          }

          return true;

    }

    function ConvertStringToDate(sDate)
    {

         var sDateArray;
         var iMonth;
         var iDay;
         var iYear;

         if (sDate.indexOf('/') != -1)
          {
               sDateArray = sDate.split('/');
              iMonth = parseInt(sDateArray[0],10);
              iDay = parseInt(sDateArray[1],10);
              iYear = parseInt(sDateArray[2],10);
          }

         return new Date(iYear, iMonth, iDay);

    }


  function checkDate(oDateElem)
  {

           var sDate = oDateElem.value;
         if (sDate == "") return true;
      
           if (sDate.length < 1)
      
          {
               return true;
          }

          if (sDate.indexOf('/') != -1)
          {
               sDateArray = sDate.split('/');
               sMonth = sDateArray[0];
               sDay = sDateArray[1];
               sYear = sDateArray[2];
          }
        else
        {
                alert('Invalid date (' + sDate + ').');
                oDateElem.focus();
                return false;
        }
         


          if (sYear.length == 1)
          {
               sYear = '200' + sYear;
          }
          if (sYear.length == 2)
          {
               sYear = '20' + sYear;
          }

          iDay = parseInt(sDay, 10);

          if (isNaN(iDay))
          {
              alert('Invalid date (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          iMonth = parseInt(sMonth, 10);
          if (isNaN(iMonth))
          {
              alert('Invalid date (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          iYear = parseInt(sYear, 10);
          if (isNaN(iYear))
          {
              alert('Invalid date (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          if (iYear < 1900 || iYear > 2078)
          {
              alert('Invalid date - year must be between 1900 and 2078 (' + sDate + ').');
              oDateElem.focus();
              return false;
          }


          if (iMonth > 12 || iMonth < 1)
          {
              alert('Invalid date - month must be between 1 and 12 (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          if ((iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12) && (iDay > 31 || iDay < 1))
          {
              alert('Invalid date - day must be between 1 and 31 (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          if ((iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) && (iDay > 30 || iDay < 1))
          {
              alert('Invalid date - day must be between 1 and 30 (' + sDate + ').');
              oDateElem.focus();
              return false;
          }

          if (iMonth == 2)
          {
               if (LeapYear(iYear) == true)
               {
                    if (iDay < 1 || iDay > 29)
                    {
                        alert('Invalid date - day must be between 1 and 29 (' + sDate + ').');
                        oDateElem.focus();
                        return false;
                    }
               }
               else
               {
                    if (iDay < 1 || iDay > 28)
                    {
                        alert('Invalid date - day must be between 1 and 28 (' + sDate + ').');
                        oDateElem.focus();
                        return false;
                    }
               }
          }

         oDateElem.value = iMonth + "/" + iDay + "/" + iYear;

          return true;
    }


    function LeapYear(iYear)
    {
         if (iYear % 100 == 0)
         {
              if (iYear % 400 == 0)
              {
                   return true;
              }
         }
         else
         {
              if ((iYear % 4) == 0)
              {
                   return true;
              }
         }
         return false;
    }

</script>
<td align="center">start
           <input maxLength="8" id="startdt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
          </td>
         <td align="center">end
           <input maxLength="8" id="enddt" size="8" onfocus="dosubmit=false;" onblur="dosubmit=checkDates();" value=""/>
          </td>
</body>
</html>
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
How about this:


<html>
<head>
<script>

 var dosubmit = true;

    function checkDates(theField)
    {
          var theForm = theField.form;
          var sStartDate;
          var sEndDate;

           if (!checkDate(theForm.startdt)) return false;
           if (!checkDate(theForm.enddt)) return false;

          sStartDate = theForm.startdt.value;
          sEndDate = theForm.enddt.value;

           dtStartDate = ConvertStringToDate(theForm.startdt.value);
           dtEndDate = ConvertStringToDate(sEndDate);

           if (dtStartDate > dtEndDate)
           {
                alert('The end date (' + sEndDate + ') is earlier than the start date (' + sStartDate + ')');
                return false;
           }

           return true;

     }

     function ConvertStringToDate(sDate)  {

          var sDateArray;
          var iMonth;
          var iDay;
          var iYear;

          if (sDate.indexOf('/') != -1)
           {
                sDateArray = sDate.split('/');
               iMonth = parseInt(sDateArray[0], 10);
               iDay = parseInt(sDateArray[1], 10);
               iYear = parseInt(sDateArray[2], 10);
           }

          return new Date(iYear, iMonth, iDay);

     }


   function checkDate(oDateElem)  {

     var sDate = oDateElem.value.split("/");
     if (sDate.length != 3) {
        return false;
     }
     iDate = new Date(oDateElem.value);
     iMonth = iDate.getMonth()+1;
     iDay = iDate.getDate();
     iYear = iDate.getFullYear();
     if(sDate[0]!=iMonth || sDate[1]!=iDay || sDate[2]!=iYear){
       alert('Invalid date.');
       oDateElem.select();
       oDateElem.focus();
       return false;
     }
     return true;
   }


</script>
</head>
<body>
<form>
<table><tr>
<td align="center">
            <input maxLength="10" name="startdt" size="10" onfocus="dosubmit=false;" onblur="dosubmit=checkDates(this);" value=""/>
           </td>
          <td align="center">
            <input maxLength="10" name="enddt" size="10" onfocus="dosubmit=false;" onblur="dosubmit=checkDates(this);" value=""/>
           </td>
</tr></table>
</form>
</body>
</html>



0
 

Expert Comment

by:ofeke
Comment Utility
The problem might be that your function is located before the input field is created?

If so - try moving the function that deals with "strtdt" to the end of your code..
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Please note that NetGrooves code will work in more browsers since it is passing the form/form field instead of usin IE only document.all
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Ofeke: You can place the function anywhere as long as it is not CALLED before the form exists
0
 

Expert Comment

by:ofeke
Comment Utility
Nope - some browsers perform "precheck" for objects. even IE do that in some cases.

Not only when you call a function - also when you cause an event, eval object etc etc
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Not in my universe....
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:TrueBlue
Comment Utility
Hi Ho_Alan!

I get the following error with the new version whether I enter a value or not.

Length is null or not an object

Chuck
0
 

Author Comment

by:TrueBlue
Comment Utility
Hi Netgroove!

I get the same error length is null or not an object with your version as well.

Any ideas?

Chuck
0
 

Author Comment

by:TrueBlue
Comment Utility
Hi Netgroove!

I was wrong I get value is null or not an object from your suggestion.

Thank you in advance.

Chuck
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
Check this:

<html>
<head>
<script>
 var dosubmit = false;

    function checkDates(theField)
    {
          var theForm = theField.form;
          var sStartDate;
          var sEndDate;

           if (!checkDate(theForm.startdt)) return false;
           if (!checkDate(theForm.enddt)) return false;

          sStartDate = theForm.startdt.value;
          sEndDate = theForm.enddt.value;

           dtStartDate = ConvertStringToDate(theForm.startdt.value);
           dtEndDate = ConvertStringToDate(sEndDate);

           if (dtStartDate > dtEndDate)
           {
                alert('The end date (' + sEndDate + ') is earlier than the start date (' + sStartDate + ')');
                return false;
           }

           return true;

     }

     function ConvertStringToDate(sDate)  {

          var sDateArray;
          var iMonth;
          var iDay;
          var iYear;

          if (sDate.indexOf('/') != -1)
           {
                sDateArray = sDate.split('/');
               iMonth = parseInt(sDateArray[0], 10);
               iDay = parseInt(sDateArray[1], 10);
               iYear = parseInt(sDateArray[2], 10);
           }

          return new Date(iYear, iMonth, iDay);

     }


   function checkDate(oDateElem)  {

     var sDate = oDateElem.value.split("/");
     if (sDate.length != 3) {
        if(oDateElem.value>""){
          alert("Inavlid Date format: "+oDateElem.value+"\nEnter Date in this format: MM/DD/YYYY");
          oDateElem.select();
          oDateElem.focus();
        }
        return false;
     }
     iDate = new Date(oDateElem.value);
     iMonth = iDate.getMonth()+1;
     iDay = iDate.getDate();
     iYear = iDate.getFullYear();
     if(sDate[0]!=iMonth || sDate[1]!=iDay || sDate[2]!=iYear){
       alert('Invalid date.');
       oDateElem.select();
       oDateElem.focus();
       return false;
     }
     return true;
   }
</script>
</head>
<body>
<form onSubmit="return dosubmit">
<table><tr>
<td align="center">
            <input maxLength="10" name="startdt" size="10" onfocus="dosubmit=false;" onblur="dosubmit=checkDates(this);" value=""/>
           </td>
          <td align="center">
            <input maxLength="10" name="enddt" size="10" onfocus="dosubmit=false;" onblur="dosubmit=checkDates(this);" value=""/>
           </td>
</tr></table>
<input type=submit>
</form>
</body>
</html>


Also is your error message not comming from my example.
Some additional code contains some typo.
Could you post your complete code for debugging?

0
 

Author Comment

by:TrueBlue
Comment Utility
Hi NetGroove!

I am sure the error is coming from this function because if I substitute:

       <input maxLength="10" name="enddt" size="10" onfocus="dosubmit=false;" onblur="dosubmit=checkDates(this);" value=""/>

with

       <input maxLength="10" name="enddt" size="10" value=""/>

I get no errors.

Here is my submission button in xslt:

  <xsl:if test="$aspemail != 'true'">
            <input type="submit" NAME="sendChanges" VALUE="Only Press Once to Send Changes">
              <xsl:attribute name="onclick"><![CDATA[ if(doSubmit) { document.form1.submit(); } ]]></xsl:attribute>
            </input>
          </xsl:if>

Here is my form code in asp:

<HTML>
  <head>
    <title>Call List Table</title>
   
     <script language="Javascript" type="text/javascript" src="datemask.js"></script>

  </head>
<body>
 <form name="form1" onsubmit="if(doSubmit) { return true; } else { return false; }" ACTION="calllist.asp" METHOD="POST">
   <input type="hidden" id="hiddeninput" value="">
   <input type="hidden" name="itemToDelete" value="">
   <input type="hidden" name=a value="<%=Request("a")%>">

Would I need to replace the phrase "theform" in your code with "form1" since that is what my form is named?

I did not include the opening / closing script tags when I copied this code to the datemask.js file.

Chuck
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
The var dosubmit has to be global defined.
And the spelling has to be always the same, not doSubmit

You get an error for this event:
  onfocus="dosubmit=false;"

Because dosubmit is not previously defined.

In xslt you even name it doSubmit

Change all vars to same name.

0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
Also the same for theForm. You can not rename it to theform or form1.
My proposal get the form reference trough the input field reference passed by reference to itself: this

0
 

Author Comment

by:TrueBlue
Comment Utility
Hi NetGroove:

I did a search and replace through my asp, xsl and js pages. The variable is now doSubmit everywhere, but I am still get the same error value is null or not an object.

Is there a way to stop the script at certain points to see where the value problem is?

Similiar to response.write sStartdt
               response.end

Thank you for you help.

Chuck
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
where is onSubmit origianly defined and initialized?
I supos it has to be defined in datemask.js

If it is nowhere initialized, then you get an error for compare in "if(doSubmit)"

0
 

Author Comment

by:TrueBlue
Comment Utility
Hi NetGroove!

I have another javascript function that checks the telephone field's format.
It is initialized I believe in there.

var doSubmit = true;

It is called by a similiar statement on the xsl page as well.

<INPUT maxLength="12" name="priphone" size="12" onfocus="doSubmit=false;"
             onblur="checkPhone(this);" onkeyup="phoneMask(this);" onkeydown="phoneMask(this);"
             value=""/>

Chuck


0
 
LVL 5

Assisted Solution

by:ho_alan
ho_alan earned 250 total points
Comment Utility
maybe u can add a function to check the invalid input first
because if the user doesn't enter properly
eg. he enters "1", then focus on the box
error will occur
0
 
LVL 10

Accepted Solution

by:
NetGroove earned 250 total points
Comment Utility
init value should be: false

like:
var doSubmit = false;

Also it is possible to change your submit button to this:

  <xsl:if test="$aspemail != 'true'">
            <input type="submit" NAME="sendChanges" VALUE="Send Changes">
              <xsl:attribute name="onclick"><![CDATA[ if(doSubmit) {doSubmit=false; this.form.submit(); } ]]></xsl:attribute>
            </input>
          </xsl:if>

This button submits now the form only if changes have been approved after the last submit.

0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
Please do not give grading B for such long running support.

Anyway, thanks for the points.
You do not know, but eperts get more points when you grade A.
If you want to do me a favor, then let correct your grading by posting a request in CS topic area:
http://www.experts-exchange.com/Community_Support/

Cheers,
NetGroove

0
 

Author Comment

by:TrueBlue
Comment Utility
Hi NetGroove!

I appreciate your help on this issue, but I was never able to get it to work.

So I just closed the question.

Chuck
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
Sorry for that.
Ok, hope next time to be of more help.

See you,
NetGroove

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now