Solved

Getting error : Object doesn't support this property or method

Posted on 2004-08-15
4
276 Views
Last Modified: 2008-01-09
Hi,

I have a javascript form with two fields that my users will use to fill in their vacation dates in - the first and last days resp. in Date1 and Date 2. Then when they click on the field DateDiff, it should show them the days between these two dates.  However I am getting the error "Object doesn't support this property or method".

PLease help. The form is below:

Thanks...

<HTML>
<HEAD>
<TITLE>Initiate</TITLE>


<script language="javascript">

LeftMar = 0
Txta = 620
F10 = 9
H10 = 9.5
F14 = 13
H14 = 13.5
F20 = 16
H20 = 16.5
F30 = 18
H30 = 18.5


function ScreenSizes(p1) {

switch (p1) {
  case 640:
 size = 614
 Txta = 612

 break

case 800:
        size = 800
        F10 = 10.5
        H10 = F10 + 0.5
        F14 = F14 * 1.25
        H14 = F14 + 0.5
        F20 = F20 * 1.25
        H20 = F20 + 0.5
        F30 = F30 * 1.25
        H30 = F30 + 0.5

case 1024:
        size = 1024
        F10 = F10 * 1.60
        H10 = F10 + 0.5
        F14 = F14 * 1.60
        H14 = F14 + 0.5
        F20 = F20 * 1.60
        H20 = F20 + 0.5
        F30 = F30 * 1.60
        H30 = F30 + 0.5

Txta = screen.width * 0.8875

break

case 1152:
        size = 1152
        F10 = F10 * 1.80
        H10 = F10 + 0.5
        F14 = F14 * 1.80
        H14 = F14 + 0.5
        F20 = F20 * 1.80
        H20 = F20 + 0.5
        F30 = F30 * 1.80
        H30 = F30 + 0.5
        Txta = screen.width * 0.8875

break


case 1280:
        size = 1280
        F10 = F10 * 2
        H10 = F10 + 0.5
        F14 = F14 * 2
        H14 = F14 + 0.5
        F20 = F20 * 2
        H20 = F20 + 0.5
        F30 = F30 * 2
        H30 = F30 + 0.5
        Txta = screen.width * 0.8875


break


case 1600:
        size = 1600
        F10 = F10 * 2.5
        H10 = F10 + 0.5
        F14 = F14 * 2.5
        H14 = F14 + 0.5
        F20 = F20 * 2.5
        H20 = F20 + 0.5
        F30 = F30 * 2.5
        H30 = F30 + 0.5
        Txta = screen.width * 0.8875
}

 }

ScreenSizes(screen.width)
LeftMar = (size-Txta)/2
with(document) {
        write('<STYLE type="text/css">')
        write('<!--')
        write('H1 {font-family:Arial, sans-serif; font-weight:700; font-size:'+F30+'pt;')
        write('line-height:'+H30+'pt; text-align:center; color:0000ff; }')
        write('H2 {font-family:Arial, sans-serif; font-weight:700; font-size:'+F20+'pt;')
        write('line-height:'+H20+'pt; text-align:center; color:0000ff; }')
        write('H3 {font-family:Arial, sans-serif; font-weight:700; font-size:'+F14+'pt;')
        write('line-height:'+H14+'pt; text-align:center; color:000000; }')
        write('H4 {font-family:Arial, sans-serif; font-weight:700; font-size:'+F14+'pt;')
        write('line-height:'+H14+'pt; text-align:left; color:000000; }')
        write('#Body-Pos {')
        write('position:absolute; left:'+LeftMar+'px; top:20px; width:'+Txta+'px; z-index:1; }')
        write('#Text-Right {')
        write('position:relative; left:0px, top:12px; width:'+Txta+'px; z-index:3;')
        write('text-align:right; }')
        write('Body {background:99cccc; vlink:000099; text:000000; }')
        write('P {font: '+F10+'pt Arial; line-height:'+H10+'pt; text-align:justify; }')
        write('A {color:ffffff; text-decoration:none; }')
        write('UL {font: '+F10+'pt Arial; line-height:'+H10+'pt; text-align:left; }')
        write('-->')
        write('</STYLE>')

}
function markDirty()
{
}


function doSubmit ( theForm )
{
for ( i = 0; i < theForm.length; i++ )
{
var tempobj = theForm.elements[ i ]
if ( tempobj.type.toLowerCase() == "button" )
{
tempobj.disabled = true;
}
}
theForm.submit();
}


function CalcVacDays(){
{

FirstDay = document.myForm._1_1_7_1.value
LastDay = document.myForm._1_1_8_1.value
var d = FirstDay.getTime() - LastDay.getTime();
//var diff = FirstDay - LastDay
document.write (d)
//document.write (LastDay)
//Firstday1 = LTrim(FirstDay)

//document.write (Firstday1)




//var days = Math.floor(diff / (1000 * 60 * 60 * 24));

//document.write("<center><h3>") +(days+1 + " days until " + description);




}

}




</SCRIPT>
</HEAD>
<BODY BACKGROUND="/actel813support/pattern.gif">
<FORM NAME="myForm" ACTION="/actel813/livelink.exe" ENCTYPE="multipart/form-data" METHOD="POST">
<h3>Vacation No Pay form 2004 </h3>
<INPUT TYPE="text" NAME="Date1" ID="Date1" VALUE="Date1" SIZE="32" MAXLENGTH="32" ONFOCUS=" " ONCHANGE="markDirty();">

<INPUT TYPE="text" NAME="Date2" ID="Date2" VALUE="Date2" SIZE="32" MAXLENGTH="32" ONFOCUS=" " ONCHANGE="markDirty();">

<INPUT TYPE="text" NAME="DateDiff" ID="DateDiff" VALUE="DateDiff" SIZE="12" MAXLENGTH="11" ONFOCUS="return CalcVacDays();" ONCHANGE="markDirty();">

<INPUT CLASS="applyButton" TYPE="BUTTON" VALUE="Subbi" NAME="IgnoreMe" ONCLICK="doSubmit(document.myForm);">



</FORM>
</BODY>
</HTML>


0
Comment
Question by:arunatata
  • 2
4 Comments
 
LVL 9

Expert Comment

by:ftaco96
ID: 11806856
It looks like "size" is not being initialized. You're probably getting through your switch...case without going into any of the cases. The n it tries to use size. You might want to initialize it at the beginning of the function: var size = 0;
0
 
LVL 1

Accepted Solution

by:
mwquek earned 250 total points
ID: 11807729
FirstDay and LastDay is not a valid date objects. So, getTime function is not supported for the both objects.

You may need to convert the Date1 and Date2 value to a valid date objects, then you will able to get the date diff.

This method will help you to convert the string value into a date object.

// convert date string in dd-mm-yyyy format to date object
function strToDate( datestr ) {
   DD1  = parseInt(datestr.substring(0,2), 10);      
   MM1  = parseInt(datestr.substring(3,5), 10);       
   YYYY1= parseInt(datestr.substring(6,10), 10);
        
   dateobj = new Date();       
   dateobj.setFullYear(YYYY1, MM1-1, DD1);    
   return dateobj;
} //end strToDate

Regards,
Quek.
0
 

Author Comment

by:arunatata
ID: 11812080
Hi Quek,

Thanks for your suggestion.  However, I am using a software to generate the fields and the form above is not an exact replica of the original fields. The original fields read the value as "D/2004/3/16:0:0:0". I tried using substring to get the 2004/3/16 from this but it gives me the error "Expected ';'"  - on a blank line - in spite of the fact that the syntax looks correct.

The code is as below (at this time i am only trying to get things working and output the entered date):

Function strToDate(datestr){
datestr = "D/2004/3/16:0:0:0";
document.write datestr;
newDate = (datestr.substring(2,10));
document.write newDate;
}


A.
0
 
LVL 1

Expert Comment

by:mwquek
ID: 11816852
Hi,

You cannot use the substring to create the date object. The date string length may be different when the month is in 1 digit or 2 digits. e.g. "D/2004/3/16..." and "D/2004/12/13"

By using the length, you may trying to create a date object with an incorrect date string. You need to fix the date string, e.g. make sure that the month in 2 digits and the day in 2 digits too. Then, you can use the substring function to get the date value.

Otherwise, you can use split function to tokenize the date string into multipart. By this, you can get the year value, month value and day value to create a valid date object.

Quek.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

792 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