gecko89 Posted November 16, 2012 Share Posted November 16, 2012 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; Link to comment Share on other sites More sharing options...
Larry Posted November 16, 2012 Share Posted November 16, 2012 Do you see any error messages in Firefox? Link to comment Share on other sites More sharing options...
gecko89 Posted November 16, 2012 Author Share Posted November 16, 2012 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. Link to comment Share on other sites More sharing options...
Larry Posted November 16, 2012 Share Posted November 16, 2012 You've misspelled textContent here: if(output.texContent !== undefined) 2 Link to comment Share on other sites More sharing options...
gecko89 Posted November 17, 2012 Author Share Posted November 17, 2012 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 . Link to comment Share on other sites More sharing options...
CindyM Posted December 10, 2012 Share Posted December 10, 2012 You've misspelled textContent here: if(output.texContent !== undefined) That same thing happened to a student of mine in her utilities.js file - she had misspelled addEventListener as addEventListenser. It took forever to find the error. Is there a validator that will catch those typos in Javascript? Link to comment Share on other sites More sharing options...
HartleySan Posted December 10, 2012 Share Posted December 10, 2012 The JS debugger built into Chrome or the free FireBug extension for Firefox. Link to comment Share on other sites More sharing options...
Recommended Posts