Valid JavaScript not working

rss

Posted by Jdubs - Dec 22 ’14 at 02:16

Scenario:

  1. I input JavaScript code, press "save," test client-side form, and form works.
  2. I input additional JavaScript code, "press save," test client-side form, and form no longer works.
  3. I remove additional JavaScript code, "press save," test client-side form, and form still does not work.

To be clear, the code from Line 1 and Line 3 are exactly the same.

Why does the code no longer work?

  • Jdubs
    Member
    Member for: 6 years 10 months 9 days
    #1 by Jdubs Dec 22 ’14 at 02:48

    Here's the EXACT scenario:

     

    Line 1 Code (Works!)

    //Calculate Date

    var calcDate = new Date();

    var Month = calcDate.getMonth() + 1;

    var Day = calcDate.getDate();

    var Year = calcDate.getFullYear();

    var vStartDate = Month + "/" + Day + "/" + Year;

    var Hour = Math.round(calcDate.getHours());

    var Minute = calcDate.getMinutes();

    var ampm = Hour >= 12 ? 'PM' : 'AM';

     

    //Pre-populate Date & Time

    if(fd.field('StartTime').value() === "")

    {

    fd.field('StartTime').value(vStartDate);

    fd.field('sTime').value(Hour + ":" + Minute + " " + ampm);

    };

     

    Line 2 (Does not work!)

    //Calculate Date

    var calcDate = new Date();

    var Month = calcDate.getMonth() + 1;

    var Day = calcDate.getDate();

    var Year = calcDate.getFullYear();

    var vStartDate = Month + "/" + Day + "/" + Year;

    var Hour = Math.round(calcDate.getHours());

    var Minute = calcDate.getMinutes();

    var ampm = Hour >= 12 ? 'PM' : 'AM';

    var 12Hour = Hour > 12 ? Hour - 12 : Hour;   //New Line of Code


    //Pre-populate Date & Time

    if(fd.field('StartTime').value() === "")

    {

    fd.field('StartTime').value(vStartDate);

    fd.field('sTime').value(Hour + ":" + Minute + " " + ampm);  //New Variable

    };

     

    Line 3 (DOES NOT WORK!)

     

    I simply un-do the two lines that I modified in Line 2, save it ... and then it doesn't work.  (even though it is EXACTLY the same as line 1)

  • Jdubs
    Member
    Member for: 6 years 10 months 9 days
    #2 by Jdubs Dec 22 ’14 at 02:50

    *sigh*  Sorry.

     

    I input variable 12Hour on Line 2 on the pre-population line.  (the one that I flag //New Variable)

     

  • Jdubs
    Member
    Member for: 6 years 10 months 9 days
    #3 by Jdubs Dec 22 ’14 at 02:54

    One additional note, I just verified this:

    When I CLEAR all the JavaScript code, SAVE it, THEN re-paste the original code, then save it again ... the JavaScript code works again.

     

Displaying 1 to 3 of 3 messages