Jump to content
Larry Ullman's Book Forums

gecko89

Members
  • Posts

    3
  • Joined

  • Last visited

gecko89's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Thank you very much, it worked. I feel dumb i have reared the code over dozen times without noticing anything. One more thing to add on my "why the script didn't work" notebook .
  2. Thanks for the response, No nothing is happening when i click on the "Submit" button. There is no page refresh, no error messages, it's like nothing is happening.
  3. Hi, everyone When i'm running the event.js script (below) on: Opera, Chrome, Safari, it work perfectly but not on Firefox. And the thing is that the original Larry Ullman version seems to work on Firefox. I think I did something wrong here is the code //begin the process() function //the process() function will do the work when the form is sunmitted function process() { 'use strict'; //get references to the HTML elements var start = document.getElementById('start'); var end = document.getElementById('end'); var output = document.getElementById('output'); // the two first vars reference the two text input. the third is a ref to the "div" output //Declare three vars fro the output var message = ''; var interval = ''; var day = 1000 * 60 * 60 * 24; //create two new Date() objects var startDate = new Date(start.value); var endDate = new Date(end.value); if( startDate.getTime() && endDate.getTime() ) { //make sure the start date comes first by a simple comparison if(startDate < endDate) { // Determine the interval between the two dates var diff = endDate - startDate; //the result will be in millisecond; if(diff <= day)//conditional if diff <= day the interval is 1 day else its several days { interval = '1 day'; }else { interval = Math.round(diff/day) + ' days'; } //generate the message to be displayed message = 'The event has been scheduled starting on ' + startDate.toLocaleDateString(); message += ' and ending on ' + endDate.toLocaleDateString(); message += ' , wich is a period of ' + interval + '.'; }else //create the errors as messages { message = 'The start date must come before the end date!'; }//end of if(startDate < endDate)... else 'message' }else { message = 'Please enter a valid start and end dates int format MM/DD/YYYY.'; }//end of if(startDate.getTime() endDate.getTime())....else 'message' //update the page with the custom message if(output.texContent !== undefined) { output.textContent = message; }else { output.innerText = message; } //complete the function return false; } //add an event listener to the form's submission function init() { 'use strict'; document.getElementById('theForm').onsubmit = process; }//end of init() function window.onload = init;
×
×
  • Create New...