Navigate
Home
ArticleWiki
Forum
Newsletter
Links
Tech News
Welcome Guest.
Username:

Password:

Remember me

Datepicker posts a value but not recognised as event
Welcome, Guest. Please login or register.
February 09, 2012, 12:59:23 AM
11513 Posts in 1262 Topics by 496 Members
Latest Member: Beerdernill
Experts Round Table Network  |  Clientside Technology  |  Javascript  |  Datepicker posts a value but not recognised as event « previous next »
Pages: [1]
Author Topic: Datepicker posts a value but not recognised as event  (Read 1026 times)
fastrobby

Offline Offline

Posts: 19


« on: July 04, 2007, 09:31:35 PM »

Hi,
I have a datepicker from Dhtml Goodies that drops a value into a text box when clicked but when I try to use the value from the text box via an on change event it doesnt recognize it's existence so the rest of my script that I use to calculate a dateOut i.e. add days to the dateIn comes up with an error in Firefox and only works on the first pass in IE .

if(thisform.document.getElementById(DateInField).value!='')          not recognised

Page in question is
http://www.kohchangbookingandinformation.com/Resorts.asp.
Click a dateIn and then Stay (no of nights) and you will come up with an error in Firefox if you have a debugger on.
At the moment I have a onfocus event in the html instead of on change as a desperate measure but that doesnt work either. I am sure there is an elegant solution but I just dont get it.
Many thanks for your time.
Robby
« Last Edit: July 04, 2007, 10:24:17 PM by fastrobby » Logged
COBOLdinosaur
ERT.com Admin

Offline Offline

Posts: 481



WWW
« Reply #1 on: July 05, 2007, 10:25:10 AM »

Code
Language: javascript (GeSHi-highlighted)
if(thisform.DateInField.value!='')

Should work

« Last Edit: July 05, 2007, 10:31:57 AM by COBOLdinosaur » Logged
COBOLdinosaur
ERT.com Admin

Offline Offline

Posts: 481



WWW
« Reply #2 on: July 05, 2007, 10:42:27 AM »

Ooops no that won't work because DateInField is a variable.  you will need some thing like:

Code
Language: javascript (GeSHi-highlighted)
if(thisform.[DateInField].value!='')
 
or perhaps
if(thisform.elements[DateInField].value!='')

IE will accept just about anything that it can find in document.all but FF requires a reference that that can be resolved through the standard DOM
Logged
VGR
Mentor

Offline Offline

Posts: 724



WWW
« Reply #3 on: July 06, 2007, 12:33:07 PM »

I think that your last suggestion, using elements[], is the good one. The shortforms recognized by IE have to ba avoided.

note also that document.thisform is a shortcut for the reference document.forms['thisform'] ;-)
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
fastrobby

Offline Offline

Posts: 19


« Reply #4 on: July 07, 2007, 01:24:37 AM »

Firstly,
Many thanks for your response.  It solved the problem and uncovered my mistake. Consequently I redisigned it to be a little more efficient and do away with an unnecessary variable. It works fine and is interactive. Pick a date get a date out and vice versa.  I am now faced with a different problem arising from an add_days to a date routine that I picked up from the web.

(1) It reverses the days and months on my parsed out string and adds days to my months. enter dateIn 06/09/2007 and  DateOut returns 09/06/2007

(2) In IE the year comes out correct say 2007 but in FF it's 107

Site in question http://www.kohchangbookingandinformation.com/resorts_2.asp

Here's the code
// date stuff
if(thisform.dateIn.value!=' ') {
   thisform.dateOut.value = addDays(thisform.dateIn.value,parseInt(thisform.nightsNo.value));
}


function addDays(DIn,days) {
var numDaysToAdd = days
var daysInMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var start = new Date(DIn);   
  if (start != ' ') {
    var y= start.getYear();
        // check for leap year (see if year divided by four leaves a remainder). If it is a leap year, add one day to February
        var remainder = y % 4;
        if (remainder == 0) {
            daysInMonth[1]=29;
        }
        var m  = start.getMonth();
        var x = start.getDate() + numDaysToAdd;
      // check for roll over into next month, and then check that for roll into next year.       
        if (x > daysInMonth[m]){
            x = x - daysInMonth[m];
            m++;
            if (m > 11){
                m=0;
                y++;
            }
        }
        // increment month to real month, not "Array" month
        m++;       
        if (x<10)
        x="0"+x
        if (m<10)
        m="0"+m
        var myDate = x+"/"+m+"/"+y;
        return myDate ;
}
}

Once again thanks for your time and expertise. PS is there a datepicker that you can recommend that can do multiple calendars per page without a lot of hassle.
Robby
« Last Edit: July 08, 2007, 07:02:43 PM by fastrobby » Logged
Pages: [1]
« previous next »
    Jump to: